分类: python |
- 1
Windows安装64位NumPy和SciPy包
作者:admin 日期:2015-12-23
到这个网站下载whl文件
http://www.lfd.uci.edu/~gohlke/pythonlibs/
注意下载和自己的python对应的版本
如何安装whl文件:
pip install whatever.whl
python socket实现一个http请求 支持gzip压缩
作者:admin 日期:2015-10-24
python用socket实现发送和接收一个http请求,自动处理gzip。直接上代码。
# -*- coding: utf-8 -*- import zlib, socket conn = socket.create_connection( ("www.zeroplace.cn", 80) ); data = "''GET / HTTP/1.1 Host: www.zeroplace.cn Accept-Encoding: gzip, deflate ''' print data conn.send(data + "\r\n") recv_data = "" header = None body = None length = 0 headers = {} buf = conn.recv(1024) html = "" while True: recv_data += buf if header is None: index = recv_data.find("\r\n\r\n") if index >= 0: header = recv_data[0:index]; recv_data = recv_data[index+4:]; header_lines = header.split("\r\n") status_line = header_lines[0] print status_line for line in header_lines[1:]: print line line = line.strip("\r\n") if len(line) == 0: continue colonIndex = line.find(":") fieldName = line[:colonIndex] fieldValue = line[colonIndex+1:].strip() headers[fieldName] = fieldValue # print headers length = int(headers['Content-Length']) if header is not None and len(recv_data) >= length: break; else: buf = conn.recv(1024) if 'Content-Encoding' in headers and headers['Content-Encoding'] == 'gzip' : html = zlib.decompress(recv_data, 16+zlib.MAX_WBITS) else: html = recv_data print html conn.close()
python hash函数
作者:admin 日期:2015-08-29
解决'ascii' codec can't encode character
作者:admin 日期:2015-04-01
- 1