python 웹 링크 추출 방법 공유

779 단어
 
  
#encoding:utf-8
import socket
import htmllib,formatter
def open_socket(host,servname):
    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    port=socket.getservbyname(servname)
    s.connect((host,port))
    return s
host=''
host=input('
')
mysocket=open_socket(host,'http')
message='GET http://%s/

'%(host,)
mysocket.send(message)
file=mysocket.makefile()
htmldata=file.read()
file.close()
parser=htmllib.HTMLParser(formatter.NullFormatter()) 
parser.feed(htmldata)
print '
'.join(parser.anchorlist)
parser.close()

좋은 웹페이지 즐겨찾기