【发布时间】:2021-07-22 09:41:42
【问题描述】:
我正在尝试从this URL 获取产品价格和名称。
当我检查 HTML 元素时,产品的价格在 span 标签下,类名为 c13VH6。
但是,我得到一个空字符串。
下面是我的代码。
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
html_text=requests.get('https://www.daraz.com.np/televisions/?
spm=a2a0e.11779170.cate_3.1.287d2d2bmERvcc',headers=headers).text
soup=BeautifulSoup(html_text, 'lxml')
#soup = BeautifulSoup(html_text, 'html5lib')
string1=soup.find('span',class_='c13VH6')
print(soup.find('span', class_='c13VH6'))
print(string1)
【问题讨论】:
-
HTML 中没有
class="c13VH6"。 -
您要查找的元素是由 JavaScript 动态添加的。你需要使用 Selenium WebDriver 之类的东西。
标签: python web web-scraping beautifulsoup