原文地址:python抓取网页,发送表单小程序
作者:xiakai06
import urllib
import urllib2
data={'a':1}#采用键值对的形式
a=urllib.urlencode(data)
#发送请求有多种方式 如urllib2.Request(r'http://....',a)或者
urllib2.urlopen(
r'http://....',a
),
#这是采用post方式
html=
urllib2.urlopen(
r'http://....',a
)
print html.read()
#这样就可以得到返回的网页。
#用get方式的话其实是拼url得到形如www.baidu.com?wd=2这种形式的网址然后打开
html=
urllib2.urlopen(
r'http://
www.baidu.com?wd=2
'
)
print html.read()
这种形式可以模拟提交表单
**************************************
httplib.HTTPConnection().request()数据为什么发送不出去!!