【发布时间】:2024-01-16 14:00:01
【问题描述】:
所以我试图从网站获取特定文本,但它只给我错误 (floor = soup.find('span', {'class': 'text-white fs-14px text-truncate attribute-value '})。文本 AttributeError: '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)
【问题讨论】:
标签: python html beautifulsoup python-requests request