Home >Backend Development >Python Tutorial >python实现网页链接提取的方法分享

python实现网页链接提取的方法分享

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 11:29:532586browse

代码如下:


#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('请输入网址\n')
mysocket=open_socket(host,'http')
message='GET http://%s/\n\n'%(host,)
mysocket.send(message)
file=mysocket.makefile()
htmldata=file.read()
file.close()
parser=htmllib.HTMLParser(formatter.NullFormatter()) 
parser.feed(htmldata)
print '\n'.join(parser.anchorlist)
parser.close()

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn