码迷,mamicode.com
首页 > 编程语言 > 详细

Python Spider - urllib.request

时间:2018-08-01 16:00:26      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:3.2   encode   realtime   exce   int   and   handle   proxy   imp   

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)

  

Python Spider - urllib.request

标签:3.2   encode   realtime   exce   int   and   handle   proxy   imp   

原文地址:https://www.cnblogs.com/Javi/p/9401484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!