初次使用urllib.requst,爬有道1.8
发布日期:2021-05-10 05:24:40 浏览次数:17 分类:精选文章

本文共 750 字,大约阅读时间需要 2 分钟。

import urllib.request

import urllib.parse
import json

���������������������

���������������������������������

content = input('���������������������������������')

���������������������������

data = {

'type': 'AUTO',
'i': content,
'doctype': 'json',
'xmlVersion': '1.8',
'keyfrom': 'fanyi.web',
'ue': 'UTF-8',
'action': 'FY_BY_CLICKBUTTON',
'typoResult': 'true'
}

���������������URL������������

data_encoded = urllib.parse.urlencode(data).encode('utf-8')

������HTTP GET������

response = urllib.request.urlopen('http://fanyi.youdao.com/translate', data=data_encoded)

������������������

html_response = response.read().decode('utf-8')

target = json.loads(html_response)

������������������

print('���������������', target['translateResult'][0][0]['tgt'])

上一篇:有道2.1,多了好多参数,爬取失败...
下一篇:python核心编程第二版第二章习题

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年04月05日 10时46分17秒