可我浪费着我寒冷的年华

python-urllib&urllib2模块

GET 

#!/usr/bin/env python
# encoding: utf-8
import urllib
import urllib2

url = "http://127.0.0.1/index.php?a=hello world"
request = urllib2.Request(url=url)
response =urllib2.urlopen(request,timeout=20)
result = unicode(response.read())
print result

POST

# encoding: utf-8
import urllib
import urllib2

url = "http://127.0.0.1/index.php"
par = urllib.urlencode({'a':1})
request = urllib2.Request(url)
opneer = urllib2.build_opener(urllib2.HTTPCookieProcessor())#所必须的
response = opneer.open(request,par)
result = response.read()
print result

 

posted @ 2017-08-17 01:08  珍惜少年时  阅读(224)  评论(0编辑  收藏  举报
可我浪费着我寒冷的年华