python get



# -*- coding: cp936 -*-
import urllib2,urllib,sys,io
"""
使用GET在百度搜索引擎上查询
此例演示如何生成GET串,并进行请求.
"""
url = "http://www.baidu.com/s"
search = [('w','codemo')]
getString = url + "?" + urllib.urlencode(search)

req = urllib2.Request(getString)
fd = urllib2.urlopen(req)
baiduResponse=""
while 1:
data= fd.read(1024)
if not len(data):
break
baiduResponse+=data
fobj=open("baidu.html",'w')
fobj.write(baiduResponse)
fobj.close()

没有更多推荐了,返回首页