爬虫----爬取答案

import requests


url = "https://www.baidu.com/s"
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
}
data = {
    "wd":"甲午中日战争什么时候开始"
}
res = requests.get(url=url,headers=headers,params=data)
res.encoding = "utf8"
html = res.text
anwsers = ["2333","1894"]
for i in range(len(anwsers)):
    anwsers[i] = (html.count(anwsers[i]),anwsers[i],i)

x = sorted(anwsers,key=lambda x:x[0],reverse=True)
print(x)

  

猜你喜欢

转载自www.cnblogs.com/yanxiaoge/p/10698161.html