【问题标题】:python urlopen output wrongpython urlopen输出错误
【发布时间】:2013-08-30 16:32:58
【问题描述】:
cj=http.cookiejar.CookieJar()
opener=build_opener(HTTPCookieProcessor(cj))
data={'uid' : uid , 'password' : password }   #uid is username to the website
data=urllib.parse.urlencode(data)
data=data.encode(encoding='utf-8')
url='http://202.117.120.37/xdjwWebNew/Servlet/UsersControl' # url is a link to a specific page
request=Request(url,data)
response=opener.open(request)
response.geturl()

输出:

'http://docs.python.org/2/library/urllib2.html?highlight=urllib'

我不知道有什么问题。 任何建议都会有所帮助。

【问题讨论】:

  • 预期的输出是什么?你问了网址,你得到了。这有什么令人惊讶的?
  • @HenryKeiter 不是这个网址。它应该返回“请求”中所需的 url,而不是 python.org。

标签: python urlopen


【解决方案1】:

您希望它输出什么?如果您想要链接中的 html 页面,请使用 response.read()。通过doc

This supports the following methods: read(), readline(), readlines()...
...these methods have the same interface as for file objects

The geturl() method returns the real URL of the page.

【讨论】:

  • 我在请求中添加了标头信息。它工作正常。请求头信息真的必要吗?
猜你喜欢
  • 1970-01-01
  • 2015-01-06
  • 1970-01-01
  • 1970-01-01
  • 2011-07-12
  • 2013-10-30
  • 1970-01-01
  • 2019-09-26
  • 2021-12-31
相关资源
最近更新 更多