我能想到的唯一方法是在Google中搜索它,并使用BeautifulSoup模块抓取结果。所以我做到了:
(抱歉,我的声誉不足以直接发布图片)
然后,我检查了搜索结果的来源: Image 2
所以我写了代码:
from bs4 import BeautifulSoup
import requests
url = 'https://www.google.com.hk/search?q=new+york+city+population&oq=New+York+&aqs=chrome.1.69i57j0l5.4853j0j7&sourceid=chrome&ie=UTF-8'
html = requests.get(url).text
soup = BeautifulSoup(html, 'lxml')
print(soup.find('div', class_ = "kpd-ans kno-fb-ctx KBXm4e"))
结果返回为None
。我该怎么办?