我实际上正在编写代码来检查链接是直接的还是错误的,还是重定向的或文件下载链接
当我写这些行
import urllib2
response = urllib2.urlopen('http://google.com')
我收到如下错误:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
response = urllib2.urlopen('http://google.com')
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 391, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 409, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 369, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1173, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1148, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 11004] getaddrinfo failed>
Y是出现任何想法的错误吗?这是因为我的公司允许以这种方式访问网站吗?谢谢
答案 0 :(得分:1)
有点晚了,但是你在浏览器中检查了http://google.com了吗?你得到了什么回应?
截至目前,HTTP连接已转发到HTTPS,这对我有用: import urllib2 response = urllib2.urlopen(&#39; http://google.com&#39;) print response.read()
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's informati
on, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for
." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta
content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script>(function(){
window.google={kEI:'WjgxV8I8jLCPA5iGn4gK',kEXPI:'1350654,3700257,3700388,4029815,4031109,4032677,4036509,4036527,4038012,4039268,4
042553,4042792,4043492,4045841,4048347,4049557,4051558,4052304,4056038,4057170,4057739,4057836,4058299,4058337,4059767,4061155,406
1181,4061552,4062222,4062287,4062299,4062333,4062407,4062632,4062706,4062971,4062987,4063095,4063111,4063126,4063829,4063879,40639
29,4064307,4064318,4064449,4064496,4064501,4064815,4064931,4065592,4065787,4065796,4065855,4065945,4066098,4066101,4066615,4066662
,4066706,4067087,4067307,8300096,8300273,8503585,8504026,8504107,8504280,8504282,8504308,8504456,8504522,10200083,10201847',authus
er:0,kscs:'c9c918f0_24'};google.kHL='en';})();(function(){google.lc=[];google.li=0;google.getEI=function(a){for(var b;a&&(!a.getAt
tribute||!(b=a.getAttribute("eid")));)a=a.parentNode;return b||google.kEI};google.getLEI=function(a){for(var b=null;a&&(!a.getAttr
ibute||!(b=a.getAttribute("leid")));)a=a.parentNode;return b};google.https=function(){return"https:"==window.location.protocol};go
ogle.ml=function(){return null};google.wl=function(a,b){try{google.ml(Error(a),!1,b)}catch(c){}};google.time=function(){return(new
Date).getTime()};google.log=function(a,b,c,e,g){a=google.logUrl(a,b,c,e,g);if(""!=a){b=new Image;var d=google.lc,f=google.li;d[f]