【发布时间】:2019-11-05 06:36:21
【问题描述】:
我想使用 Python 的 BeautifulSoup 库从 Google 财经中抓取数据(例如,市值、市盈率等)。但是,当我尝试使用“find_all”功能从相应的 Google 财经网站的 html 代码中提取某些段落(如“div”、“tr”、“td”)时,我总是收到一个空列表(即,下面代码中的“base”对象为空)。
在调试过程中,我打印了“汤”对象并将其内容与相应的 html 代码进行比较。令我惊讶的是“汤”对象的内容与 html 代码的内容不同。我希望两者都应该匹配才能成功提取数据。
from bs4 import BeautifulSoup
import urllib.request
opener = urllib.request.build_opener()
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
response = opener.open('https://www.google.com/search?q=NASDAQ:GOOGL')
soup = BeautifulSoup(response, 'html.parser')
base = soup.find_all('div',{'class':'ZSM8k'})
print(soup)
print(base)
【问题讨论】:
标签: python web-scraping beautifulsoup