爬虫基础 爬取有道词典制作pycharm英汉互译快捷方式
程序员文章站
2022-05-04 11:45:14
...
import requests
headers = {
'User-Agent':"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41",
}
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
kw = input('你想查啥呢?')
data = {
"i":kw,
"from":"AUTO",
"to":"AUTO",
"smartresult":"dict",
"client":"fanyideskweb",
"salt":"15989444246067",
"sign":"a78ec3e687d148700ef821362b7db2d5",
"lts":"1598944424606",
"bv":"876437fffef40414c50e22b60815b7dc",
"doctype":"json",
"version":"2.1",
"keyfrom":"fanyi.web",
"action":"FY_BY_REALTlME",
}
#post请求需加data
response = requests.post(url=url,headers=headers,data=data)
# print(response.text)
res = response.json()
# print(res)
#此处用到列表获取元素的方法
results = res['translateResult'][0][0]['tgt']
print(results)
上一篇: {"errorCode":50}爬取有道词典的翻译
下一篇: python 爬取ip地址