熊咪

爬虫学习---模拟提交

import urllib
import urllib.request
import http.cookiejar

cookie = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie))

#需要POST的数据#
postdata=urllib.parse.urlencode({
'uid':'1111111',
'password':'11111',
'range':2,
'operation':'connect',
'timeout':'1'
})

#自定义一个请求#
req = urllib.request.Request(
url = 'http://ipgw.neu.edu.cn/ipgw/ipgw.ipgw',
data = postdata.encode(encoding='UTF8')
)

#访问该链接#
result = opener.open(req)

#打印返回的内容#
print (result.read())

posted on 2015-05-15 11:13  熊咪  阅读(227)  评论(0编辑  收藏  举报