BeautifulSoup如何提取<td>下的span
本帖最后由 shenshuai 于 2020-8-16 00:32 编辑大佬们,我现在想提取一段字符串(629,088 in Automotive),如图所示。但是这里貌似什么有用的标签都没有。请问应该怎么用beautifulSoup提取他呢?
这是网页地址:https://www.amazon.com/dp/B071HVG69S
body绑定了js事件,直接拿不到你的html元素,估计得用selenium。
soup.find("td").span 我没搜到你说的这个字符串,,如果资料在js里面的话就需要用json模块..分析字典类型的数据.用BeautifulSoup是分析xml格式的,并不能分析json如果要分析json先把接口找到来,然后发论坛,我再给你写段代码,你看我帖子,我最近有发例子 手写的,没经过调试,不知道行不行
#soup是BeautifulSoup对象
table = soup.find("div", id="productDetails_db_sections").find("div", class_="a-section table-padding").find("table")
trs = table.find_all("tr")
st = "" # 要提取的字符串
for tr in trs:
td = tr.find("td")
if td.text().find("Automotive") > 0:
st = td.text()
break 感谢各位大佬的回答,我用了笨办法做出来了,我用re模块,给大家借鉴一下
level_category = soup.find(id='productDetails_detailBullets_sections1')# 获取一级和二级排名
content = str(level_category)
reg = '<span>#(.*?) in'
result = re.findall(reg, content)
我觉得parsel模块也不错,用css选择器
页:
[1]