Kingdict – ECommerce Observer

To Make Speaking Easier across world

Python WEB 客户端编程

HTTP基于请求和回应(requests &responses )-客户端制造请求服务器返回回应。urlib2用代表了你正在请求的HTTP request的Request对象反映了这些。调用urlopen函数对请求的url返回一个respons对象。这个respons是一个像file的对象,这意味着你能用.read()函数操作这个respon对象: req = urllib2.Request(‘http://www.voidspace.org.uk’) response = urllib2.urlopen(req) the_page = response.read() url = ‘http://www.someserver.com/cgi-bin/register.cgi’ user_agent = ‘Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)’ values = {‘name’ : ‘Michael Foord’, ‘location’ : ‘Northampton’, ‘language’ : ‘Python’ } headers = { ‘User-Agent’ : user_agent } data = urllib.urlencode(values) req = urllib2.Request(url, data, headers) response = urllib2.urlopen(req) [...]

Python处理中文知识

Python will default to ASCII as standard encoding if no other encoding hints are given. # coding= # -*- coding: -*- 中文 coding:cp936 文件中指定的编码要和实际相符合,否则的话python会报错 Python’s tokenizer/compiler combo will need to be updated to work as follows: 1. read the file 2. decode it into Unicode assuming a fixed per-file encoding 3. convert it into a [...]