# -*- coding: cp936 -*- import urllib2,urllib,sys """ 使用GET在百度搜索引擎上查询 在百度的搜索条中随便输入一些内容,会有w和cl两项构成GET串 此例演示如何生成GET串,并进行请求. """ url = "http://www.baidu.com/s" search = [('w','python'),('cl','3')] getString = url + "?" + urllib.urlencode(search) req = urllib2.Request(getString) fd = urllib2.urlopen(req) while 1: data = fd.read(1024) if not len...
发现python里面扩展了日志打印功能。感觉比java自带的还好,和log4j很类似。 下面总结下其用法。先说一种不用配置文件的: 1 # -*- coding: gb2312 -*- 2 import logging 3 4 logging.basicConfig(level=logging.INFO, 5 format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', 6 datefmt='%m-%d %H:%M', 7 filename='./AutoUpdate.log', 8 ...
本帖最后由 meto2009 于 2013-04-06 21:03 编辑 from poster.encode import multipart_encode from poster.streaminghttp import register_openers import urllib2 register_openers() datagen, headers = multipart_encode({'file':open('test.txt', 'rb')}) request = urllib2.Request('http://127.0.0.1:8080/', datagen, headers) response = urllib2.urlopen(request) print response.read() 文件是上传上去了,但是报如下...