import urllib,urllib2
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php'
print urllib2.urlopen(url).read()
print urllib2.urlopen(url,urllib.urlencode({'nothing':12345})).read()
我遇到的问题是,为什么两个“打印”输出相同的内容, 凡在我的代码是什么问题?
import urllib,urllib2
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php'
print urllib2.urlopen(url).read()
print urllib2.urlopen(url,urllib.urlencode({'nothing':12345})).read()
我遇到的问题是,为什么两个“打印”输出相同的内容, 凡在我的代码是什么问题?
urlopen的第二个参数是要发布的数据。如果您想URL参数,你需要创建的网址:
print urllib2.urlopen("%s?%s" % (url,urllib.urlencode({'nothing':12345}))).read()
显然,你正在联系该网站是忽略了字符串'什么= 12345'您在POST请求发送。对我来说似乎很合理。 –
我只是喜欢pythonchallenge是用PHP编写的。 – geoffspear
@SvenMarnach你是对的 – shellfly