benutze python 2.6 und habe folgendes Problem mit dem folgenden Code um Links auslesen:
Code: Alles auswählen
from httplib import *
import re
def getLinks(url):
conn = httplib.HTTPConnection(url)
conn.request('GET' , '/')
antw = conn.getresponse()
html = antw.read()
p = re.compile('(?<=href=")(.*?)(?=")')
link_matches = p.findall(html)
return link_matches
print getLinks('www.touristiklinks.de/')
File "C:\...", line 8, in <module>
conn = httplib.HTTPConnection(url)
NameError: name 'httplib' is not defined
Das Modul ist als Standartmodul vorhanden, soweit ich weiß?!
Als ziemlicher Anfänger hab ich wirklich keinen Blassen...
ohne die Basisklassenbenennung vor HTTPConnection(url)
also "conn = HTTPConnection(url)"
bekomm ich folgende Fehlermeldungen:
Traceback (most recent call last):
File "C..." line 20, in <module>
print getLinks('www.touristiklinks.de/')
File "...", line 12, in getLinks
conn.request('GET' , '/')
File "C:\Python26\lib\httplib.py", line 874, in request
self._send_request(method, url, body, headers)
File "C:\Python26\lib\httplib.py", line 911, in _send_request
self.endheaders()
File "C:\Python26\lib\httplib.py", line 868, in endheaders
self._send_output()
File "C:\Python26\lib\httplib.py", line 740, in _send_output
self.send(msg)
File "C:\Python26\lib\httplib.py", line 699, in send
self.connect()
File "C:\Python26\lib\httplib.py", line 683, in connect
self.timeout)
File "C:\Python26\lib\socket.py", line 498, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed
Vielleicht kann mir jemand helfen...
ist es der falsche http port?