我正在编写一个网络抓取工具,以提取出现在搜索结果页面左上角的谷歌搜索中的搜索结果数量。我写了下面的代码,但我不明白为什么phrase_extract 是 None 。我想提取短语“大约 12,010,000,000 个结果”。我在哪一部分犯了错误?可能是 HTML 解析不正确?
import requests
from bs4 import BeautifulSoup
def pyGoogleSearch(word):
address='http://www.google.com/#q='
newword=address+word
#webbrowser.open(newword)
page=requests.get(newword)
soup = BeautifulSoup(page.content, 'html.parser')
phrase_extract=soup.find(id="resultStats")
print(phrase_extract)
pyGoogleSearch('world')
Run Code Online (Sandbox Code Playgroud)
