这个非常简单的HTML代码(网址很难看,但很简单)很简单。例如,如果您键入" hi"进入textarea并点击“提交”,它会显示您期望的页面:无法找到包含跟踪号码的包裹的内容"嗨"。
<form action="http://www.chronopost.fr/transport-express/livraison-colis/accueil/suivi?appid=9680_718&appparams=http%3A%2F%2Fwww.chronopost.fr%3A54711%2Fwebclipping%2Fservlet%2Fwebclip%3Fjahia_url_web_clipping%3Dhttp%3A%2F%2Flocalhost%3A54702%2Fexpedier%2FinputLTNumbers.do&resetAppSession=true#field_9680" method="post">
<textarea name="chronoNumbers"></textarea>
<input type="submit" />
</form>
如果我尝试在python中执行等效操作:
#! /usr/bin/python
import urllib
import urllib2
url = "http://www.chronopost.fr/transport-express/livraison-colis/accueil/suivi?appid=9680_718&appparams=http%3A%2F%2Fwww.chronopost.fr%3A54711%2Fwebclipping%2Fservlet%2Fwebclip%3Fjahia_url_web_clipping%3Dhttp%3A%2F%2Flocalhost%3A54702%2Fexpedier%2FinputLTNumbers.do&resetAppSession=true#field_9680"
values = {"chronoNumbers": "hi"}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
with open("outfile.html", "w") as outfile:
outfile.write(the_page)
结果页面改为&#34;异常加载应用程序数据&#34;。当我使用&#34;请求&#34;时,我会得到相同的行为。包而不是&#34; urllib&#34;。
有人知道结果不同的原因吗?