从<跨度类获取文本:使用美丽汤和请求



所以我试图从网站获取特定的文本,但它只给了我错误(floor=汤.found('span',{'class':'text white fs-14px text truncate attribute value'(.textAttributeError:"NoneType"对象没有属性"text"(

我特别想获得"最低价格"文本。

我的代码:

import bs4
from bs4 import BeautifulSoup
#target url
url = "https://magiceden.io/marketplace/solsamo"
#act like browser
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
response = requests.get('https://magiceden.io/marketplace/solsamo')
#parse the downloaded page
soup = BeautifulSoup(response.content, 'lxml')
floor = soup.find('span', {'class': 'text-white fs-14px text-truncate attribute-value'}).text
print(floor)

之后,HTML中没有所需的数据

response = requests.get('https://magiceden.io/marketplace/solsamo')

您可以通过查看页面源代码来确保这一点:

view-source:https://magiceden.io/marketplace/solsamo

您应该使用Selenium而不是requests来获取数据,或者您可以在这个页面上检查XHR请求,也许您可以通过以下其他链接使用requests来获取这些数据。

最新更新