如何从]中刮取文本> 元素“ id” 我正在学习如何抓取,那么我还不是很先进。我从彭博社刮掉公司的介绍。例如从此页面(https://www.bloomberg.com/research/stocks/private/snapshot.asp?privcapId=320105) 我想刮擦 <p id="bDescTeaser" itemprop="description">Fiat Chrysler Automobiles N.V., ...</p> 我的脚本: from urllib.request import Request, urlopen from bs4 import BeautifulSoup html= 'https://www.bloomberg.com/research/stocks/private/snapshot.asp? privcapId=32010' page = urlopen(html) data = BeautifulSoup(page, 'html.parser') text = data.find('p',id="bDescTeaser",itemprop=" ") print(text.get_text)) 如果我尝试运行获得的程序, AttributeError: 'NoneType' object has no attribute 'get_text' 这是我的代码还是此特定Webapge的问题? 我正在学习如何抓取,那么我还不是很先进。我从彭博社刮掉公司的介绍。例如从此页面(https://www.bloomberg.com/research/stocks/private/snapshot ....

问题描述 投票:0回答:2

我正在学习如何抓取,那么我还不是很先进。我从彭博社刮掉公司的介绍。例如从此页面(https://www.bloomberg.com/research/stocks/private/snapshot.asp?privcapId=320105

python web-scraping beautifulsoup nonetype
2个回答
2
投票

在您的解决方案中,彭博阻止您的请求。因为它认为您是机器人。您应该使用请求库并将用户代理发送为标头。这样您将获得预期的输出。


0
投票

get_text()必须带有一个开放的括号。将其从get_text)更改为get_text()

© www.soinside.com 2019 - 2024. All rights reserved.