爬取有道词典代码
作者:互联网
import requests while True: url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule' kw = input('请输入单词:') header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'} data = {'i':kw ,'doctype': 'json'} response = requests.post(url=url,data=data,headers=header); response.raise_for_status() response.encoding = response.apparent_encoding resdata = response.json() print(resdata['translateResult'][0][0]['src']+':'+resdata['translateResult'][0][0]['tgt'])
爬取有道词典
标签:encoding,url,代码,resdata,response,爬取,header,data,词典 来源: https://www.cnblogs.com/YanZhuDL/p/14519995.html