使用python开发简单的贴吧爬虫代码及python ide问题
贴吧例子代码来源于csdn网站,感谢作者技术分享,受益匪浅。
import binasciiimport socketimport structimport sys#create a TCP/IP socket# sock = socket.socket(socket.AF_INET6,socket.SOCK_STREAM)sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)server_addr = ('',10000)sock.bind(server_addr)sock.listen(10)unpacker = struct.Struct('I 2s f')while True: print >>sys.stderr , '\n waiting for a client' conn, client_addr = sock.accept() try: data = conn.recv(unpacker.size()) unpacked_data = unpacker.unpack(data) finally: conn.close()