【发布时间】:2018-09-08 04:37:14
【问题描述】:
如果我用谷歌搜索 How old is Messi,它应该给我输出:30,但它会回答我 None。
我正在使用 Python 3。
import time
from bs4 import BeautifulSoup
import requests
search=input("What do you want to ask: ")
search=search.replace(" ","+")
link="https://www.google.com/search?q="+search
print(link)
source=requests.get(link).text
soup=BeautifulSoup(source,"html.parser")
print(soup.prettify())
answer=soup.find('div',class_="Z0LcW")
print(answer.text)
【问题讨论】:
-
@vadimKotov 我的答案在“div”下,类别为“Z0LcW”
标签: python web-scraping beautifulsoup