标签:class open gen pytho div color head read scheme
工具:
python+urllib2
用法:
import urllib2 ueser-agent = ‘user‘ #方法一 headers ={‘User-agent‘:ueser-agent} request = urllib2.Request(url,headers = headers) #方法二 request = urllib2.Request(url) request.add_header(‘User-agent, ueser-agent) response = urllib2.urlopen(request).read() print(response)
访问外国网站的代理方案
import urllib2 ueser-agent = ‘user‘ headers ={‘User-agent‘:ueser-agent} request = urllib2.Request(url,headers = headers) opener = urllib2.build_opener() proxy_params = {urlparse.urlparse(url).scheme:proxy} opener.add_heandler(urllib2.ProxyHandler(proxy_params)) res = opener.open(request).read() print(res)
标签:class open gen pytho div color head read scheme
原文地址:https://www.cnblogs.com/navysummer/p/9938494.html