爬虫 代理问题
来源:互联网 发布:卫龙淘宝店不火 编辑:程序博客网 时间:2024/04/30 09:08
1
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\anzhuang\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 682, in runfile execfile(filename, namespace) File "D:\anzhuang\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "D:/python/useProxyAndSurf.py", line 30, in <module> doc = url_user_agent(url) File "D:/python/useProxyAndSurf.py", line 23, in url_user_agent html = urllib2.urlopen(req) File "D:\anzhuang\Anaconda\lib\urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "D:\anzhuang\Anaconda\lib\urllib2.py", line 431, in open response = self._open(req, data) File "D:\anzhuang\Anaconda\lib\urllib2.py", line 449, in _open '_open', req) File "D:\anzhuang\Anaconda\lib\urllib2.py", line 409, in _call_chain result = func(*args) File "D:\anzhuang\Anaconda\lib\urllib2.py", line 1227, in http_open return self.do_open(httplib.HTTPConnection, req) File "D:\anzhuang\Anaconda\lib\urllib2.py", line 1197, in do_open raise URLError(err)urllib2.URLError: <urlopen error [Errno 10060] >
问题原因:代理出现问题。
类似的简单解决方法
方法1:
import urllib2proxy_support = urllib2.ProxyHandler({"http":"http://61.233.25.166:80"})opener = urllib2.build_opener(proxy_support)urllib2.install_opener(opener)html = urllib2.urlopen("http://www.google.com").read()print html
方法2
import urllib2#proxy = "61.233.25.166:80"proxy = "YOUR_PROXY_GOES_HERE"proxies = {"http":"http://%s" % proxy}url = "http://www.google.com/search?q=test"headers={'User-agent' : 'Mozilla/5.0'}proxy_support = urllib2.ProxyHandler(proxies)opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler(debuglevel=1))urllib2.install_opener(opener)req = urllib2.Request(url, None, headers)html = urllib2.urlopen(req).read()print html
0 0
- 爬虫 代理问题
- 爬虫代理
- java爬虫代理
- 爬虫代理ip设置
- 爬虫代理ip设置
- 爬虫自动更换代理
- python网页爬虫代理
- Python爬虫代理池
- python爬虫07--代理
- 爬虫代理IP
- 爬虫设置代理
- Python 爬虫IP代理
- 爬虫 IP代理策略
- Python爬虫走代理
- java爬虫代理
- 构建爬虫代理池
- 如何选择爬虫代理?
- python爬虫用户代理
- Jmeter知识点链接整理(我只是个搬运工)
- eclipse 中 Android 项目依赖文件管理
- [other]csdn 账号登陆不上去,需移除 Cookie
- maven surefire 插件源码修改,自定义输出格式
- atof(),atoi(),itoa(),sprintf()函数详解
- 爬虫 代理问题
- win10企业版激活方法
- 配置item2
- Linux下使用screen工作How-to
- 异常的一些经典问题
- 实现小程序:返回给定文件描述符的文件标志说明
- [Bluetooth Core V4.2] VOL2, PartB, 7 Bitstream Processing
- C++构造函数的继承问题
- jquery的ajax和getJson跨域获取json数据