Python Spider - urllib.request
Posted Javi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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:_DiskdocumentsourcePythonspider.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的主要内容,如果未能解决你的问题,请参考以下文章