proxy = 'http://127.0.0.1:80'
opener = urllib2.build_opener(urllib2.ProxyHandler({'http': proxy}))
req = urllib2.Request("http://www.baidu.com", '', headers)
urllib2.install_opener(opener)
response = urllib2.urlopen(req).read()
with open('j:/01' + ".srt", "wb") as subtitle:
subtitle.write(response)
出错信息如下
"I:\Program Files\python27\python.exe" C:/test.py
Traceback (most recent call last):
File "C:/test.py", line 13, in <module>
response = urllib2.urlopen(req).read()
File "I:\Program Files\python27\lib\urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "I:\Program Files\python27\lib\urllib2.py", line 404, in open
response = self._open(req, data)
File "I:\Program Files\python27\lib\urllib2.py", line 422, in _open
'_open', req)
File "I:\Program Files\python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "I:\Program Files\python27\lib\urllib2.py", line 1214, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "I:\Program Files\python27\lib\urllib2.py", line 1184, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10061] >
Process finished with exit code 1