Как мне добавить тег <li>
и </li>
к каждой строке в переменной списка bullets_text
Текущий результат:
24.2MP APS-C CMOS Sensor DIGIC 6 Image Processor
3.0" 1.04m-Dot Vari-Angle Touchscreen Full HD 1080p Video Recording at 60 fps
Желаемый результат:
<li>24.2MP APS-C CMOS Sensor</li> <li>DIGIC 6 Image Processor</li>
<li>3.0" 1.04m-Dot Vari-Angle Touchscreen</li> <li>Full HD 1080p Video
Recording at 60 fps</li>
Текущий код:
from bs4 import BeautifulSoup
import urllib.request
import pandas as pd
def get_bullets(urls):
urls = urls.split(",")
dfs = []
for url in urls:
page = urllib.request.urlopen(url)
soup = BeautifulSoup(page,'lxml')
sku = url.split('/')[5]
content = soup.find('div', class_='js-productHighlights product-highlights c28 fs14 js-close')
bullets = content.find_all('li', class_='top-section-list-item')
bullets_text = '\n'.join([ bullet.text for bullet in bullets ])
temp_df = pd.DataFrame([[sku, bullets_text]], columns = ['sku','bullets'])
dfs.append(temp_df)
df = pd.concat(dfs, ignore_index=True)
df.to_csv('book2.csv', index=False)
get_bullets(input('enter url'))
пользовательский ввод: https://www.bhphotovideo.com/c/product/1225875-REG/canon_1263c004_eos_80d_dslr_camera.html