繁体   English   中英

"美丽的汤发现问题"

[英]Beautiful Soup find issue

我正在尝试使用 Python->Beautiful Soup 解析网页,加载大约 2 秒后的文本仅出现:[1]这是关于提取的 HTML 的图像<\/a>

我正在尝试提取突出显示(已售罄)的内容。

但我有一个错误代码

price = soup.find('button', attrs={'class':'ncss-btn-primary-dark  btn-lg btn-lg disabled'}).text AttributeError: 'NoneType' object has no attribute 'text'

很好的尝试,.text 将其更改为 #.text 并提到 attrs={'class': 'ncss-btn-primary-dark'}。

如果你不明白,请看下面的代码,特别是属性。

按照下面提到的代码它将起作用。

from bs4 import BeautifulSoup
s = """
<button type="button" class="ncss-btn-primary-dark  btn-lg btn-lg disabled">Sold Out</button>
"""
soup = BeautifulSoup(s, 'html.parser')

#print(soup.find('button', {'class': 'whatever class name mentioned on your code type here and try'}).text)
print(soup.find('button', {'type': 'button'}).text)

#(or) this below mentioned attribute method also working
print(soup.find('button', attrs={'type': 'button'}).text)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM