I'm just playing around and I'm trying to grab information from websites. Unfortunately, with the following code:
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')
I get the following error:
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')
The only time I do not get an error is if the url passed is http://www.reddit.com. Every other url I have tried comes up with the socket.gaierror. Can anyone explain this? And possibly give a solution?