一、下载一只猫
1 import urllib.request
2 response = urllib.request.urlopen('http://api.zhuazhuale.4utec.cn:9107/dolliconimage/20180223/15193660137911.jpg')
3 cat_img = response.read()
4 with open('cat.jpg','wb') as f:
5 f.write(cat_img)
二、翻译文本
1 import urllib.request
2 import urllib.parse
3
4 url = "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"
5 data = {}
6 data['type'] = 'AUTO'
7 data['i'] = 'I love FishC.com'
8 data['doctype'] = 'json'
9 data['xmlVersion'] = '1.6'
10 data['keyfrom'] = 'fanyi.web'
11 data['ue'] = 'UTF-8'
12 data['typoResult'] = 'true'
13 data = urllib.parse.urlencode(data).encode('utf-8')
14 response = urllib.request.urlopen(url,data)
15 html = response.read().decode('utf-8')
16 print(html)