【发布时间】:2012-07-29 14:42:48
【问题描述】:
我用python2.6写了如下代码,想改成python3.2和Requests:
import urllib, urllib2
import cookielib
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
params = urllib.urlencode(dict(x = '0' , y = '0', url='login.php', password='1234',id='userid'))
f = urllib2.urlopen('http://test.com/login_check.php', params)
data = f.read()
login_response = opener.open('http://aaa.com/bbs/confirm.php?')
htmlContent = login_response.read()
print htmlContent
response.close()
【问题讨论】:
-
.. I want change it to python3.2 and Requests-- 这不是一个坏主意 -- 去吧。通读docs.python-requests.org/en/latest/index.html 应该使您能够编写所需的函数调用。附带说明:您发布的代码将为response.close()引发NameError(也许这应该是login_response.close())
标签: python python-3.x python-requests