python爬虫爬取百度翻译(post请求)
程序员文章站
2022-03-27 22:33:28
1.需求爬取网址:https://fanyi.baidu.com二、代码实现import requestsurl = "https://fanyi.baidu.com/sug"data = { "kw":input(">")}headers = { "user-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/...
1.需求
爬取网址:https://fanyi.baidu.com
二、代码实现
import requests
url = "https://fanyi.baidu.com/sug" data = { "kw":input(">") } headers = { "user-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36", } #发送post请求 response = requests.post(url=url,data=data,headers=headers) #获取返回内容,这里是json,获取json数据转字典 content = response.json() #获取数据 print(content["data"][0]["v"])
三、运行结果
本文地址:https://blog.csdn.net/weixin_50843522/article/details/109020796
下一篇: 怎么利用淘口令快速提升网店流量?