Home >Backend Development >Python Tutorial >python抓取网页内容示例分享

python抓取网页内容示例分享

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

代码如下:


import socket
def open_tcp_socket(remotehost,servicename):
    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    portnumber=socket.getservbyname(servicename,'tcp')
    s.connect((remotehost,portnumber))
    return s
mysocket=open_tcp_socket('www.taobao.com','http')
mysocket.send('hello')
while(1):
    data=mysocket.recv(1024)
    if(data):
        print data.decode('gbk').encode('utf-8')#对于gbk编码网页必须这样转化一下
    else:
        break
mysocket.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