我只是在玩,我试着从网站上获取信息。不幸的是,使用以下代码:import sys
import socket
import re
from urlparse import urlsplit
url = urlsplit(sys.argv[1])
sock = socket.socket()
sock.connect((url[0] + '://' + url[1],80))
path = url[2]
if not path:
path = '/'
print path
sock.send('GET ' + path + ' HTTP/1.1\r\n'
+ 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.3.154.9 Safari/525.19\r\n'
+ 'Accept: */*\r\n'
+ 'Accept-Language: en-US,en\r\n'
+ 'Accept-Charset: ISO-8859-1,*,utf-8\r\n'
+ 'Host: 68.33.143.182\r\n'
+ 'Connection: Keep-alive\r\n'
+ '\r\n')
我得到以下错误:Traceback (most recent call last):
File
"D:\Development\Python\PyCrawler\PyCrawler.py",
line 10, in
sock.connect((url[0] + '://' + url[1],80)) File "", line 1,
in connect socket.gaierror: (11001,
'getaddrinfo failed')
我唯一没有得到错误的时候是传递的url是http://www.reddit.com。我尝试过的其他网址插座盖错误. 有人能解释一下吗?可能会给出一个解决方案?在