37,720
社区成员
发帖
与我相关
我的任务
分享
class getSockPost():
def __init__(self):
self.url="http://forum.xitek.com/thread-1444940-1-1-1.html"
self.user_agent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'
self.headers = {'User-Agent': self.user_agent, 'Host':'forum.xitek.com'}
def getContent(self):
cookie=cookielib.CookieJar()
cookie_support=urllib2.HTTPCookieProcessor(cookie)
opener=urllib2.build_opener(cookie_support)
urllib2.install_opener(opener)
print home
Req=urllib2.Request(self.home,headers=self.headers)
print "1"
Resp=urllib2.urlopen(Req)
print "2"
content=Resp.read().decode('gb2312','ignore')
print "done"
print content
if __name__=="__main__":
print "work"
obj=getSockPost()
obj.getContent()
Traceback (most recent call last):
File "C:/Kingsoft/Python/coding/getStockPostXitek.py", line 33, in <module>
obj.getContent()
File "C:/Kingsoft/Python/coding/getStockPostXitek.py", line 23, in getContent
Resp=urllib2.urlopen(Req)
File "C:\Python27\lib\urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 404, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 422, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1214, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1187, in do_open
r = h.getresponse(buffering=True)
File "C:\Python27\lib\httplib.py", line 1067, in getresponse
response.begin()
File "C:\Python27\lib\httplib.py", line 409, in begin
version, status, reason = self._read_status()
File "C:\Python27\lib\httplib.py", line 365, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "C:\Python27\lib\socket.py", line 476, in readline
data = self._sock.recv(self._rbufsize)
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Process finished with exit code 1