【发布时间】:2017-07-24 12:04:02
【问题描述】:
我正在尝试使用 BeautifulSoup.find 解析淘宝网站并获取有关商品的信息(照片、文本和链接),但它没有找到所有类。
url='https://xuanniwen.world.tmall.com/category-1268767539.htm?search=y&catName=%BC%D0%BF%CB#bd&view_op=citations_histogram'
def get_html(url):
r = requests.get(url)
return r.text
html=get_html(url)
soup=BeautifulSoup(html, 'lxml')
z=soup.find("div",{"class":"J_TItems"})
z-为空。 但例如:
z=soup.find("div",{"class":"skin-box-bd"})
len(z)
Out[196]: 3
工作正常
为什么这种方法不起作用?我应该怎么做才能获得所有关于好的信息?我正在使用 python 2.7
【问题讨论】:
-
尝试
soup.text.find("J_TItems"),你会看到它会说soup中根本没有J_TItems,我认为正在发生的事情是你要解析的内容不在html中,实际上是由 JavaScript 动态构建的,你应该看看 Python 的 selenium 模块。
标签: python parsing beautifulsoup