简体   繁体   English

"美丽的汤发现问题"

[英]Beautiful Soup find issue

I am trying to parse a webpage with Python->Beautiful Soup and the text after loading about 2seconds only appear: [1] Here is the Image about the HTML about the extract<\/a>我正在尝试使用 Python->Beautiful Soup 解析网页,加载大约 2 秒后的文本仅出现:[1]这是关于提取的 HTML 的图像<\/a>

I am trying to extract the contents of the highlighted (Sold Out).我正在尝试提取突出显示(已售罄)的内容。

price = soup.find('button', attrs={'class':'ncss-btn-primary-dark'})<\/code>

But I have an error code with this但我有一个错误代码

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

Well nice try, .text change it as #.text and mentioned attrs={'class': 'ncss-btn-primary-dark'}.很好的尝试,.text 将其更改为 #.text 并提到 attrs={'class': 'ncss-btn-primary-dark'}。

If you are not understood please see below code in,particularly attribute.如果你不明白,请看下面的代码,特别是属性。

Follow this below mentioned code it will work.按照下面提到的代码它将起作用。

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