Python Spider - urllib.request

import urllib.request
import urllib.parse
import json

proxy_support = urllib.request.ProxyHandler({'http':'http://10.3.246.5:8500'})
opener = urllib.request.build_opener(proxy_support, urllib.request.HTTPHandler)
urllib.request.install_opener(opener)

data = {}
data['from'] = 'en'
data['to'] = 'zh'
data['query'] = 'Most solar heating systems use large aluminum or alloy sheets, painted black to absorb the sun\'s heat. '
data['transtype'] = 'realtime'
data['simple_means_flag'] = '3'
data = urllib.parse.urlencode(data).encode('utf-8')

resp=urllib.request.urlopen("http://www.eoeit.cn/lianhanghao/index.php?bank=&key=&province=&city=&page=1",data)
html=resp.read().decode('utf-8')

path="C:\Z_Disk\document\source\Python\spider.txt"
try:
    with open(path,"w", encoding='utf-8') as wr:
        wr.write(str(html))
except Exception as e:
    print(e)

  

posted @ 2018-08-01 15:25  Javi  阅读(270)  评论(0编辑  收藏  举报