爬虫----爬取答案


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)

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM