在python中获取HTTPS标头

发布于 2024-11-16 15:22:34 字数 1252 浏览 14 评论 0原文

我正在处理 HTTPS,我想获取 live.com 的 HTTP 标头

import urllib2

try:
    email="[email protected]"
    response = urllib2.urlopen("https://signup.live.com/checkavail.aspx?chkavail="+email+"&tk=1258056184535&ru=http%3a%2f%2fmail.live.com%2f%3frru%3dinbox&wa=wsignin1.0&rpsnv=11&ct=1258055283&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1036&id=64855&bk=1258055288&rollrs=12&lic=1")
    print 'response headers: "%s"' % response.info()
except IOError, e:
    if hasattr(e, 'code'): # HTTPError
        print 'http error code: ', e.code
    elif hasattr(e, 'reason'): # URLError
        print "can't connect, reason: ", e.reason
    else:
        raise

,所以我不需要标头中的所有信息,

如果您询问脚本的作用,我只需要 Set-Cookie 信息: 从该病毒 CheckAvail= 获取金额,

它用于检查电子邮件是否可在 hotmail 中使用,方法是编辑后

感谢帮助..修复仅获取 Set-Cookie 后,我遇到了问题当我得到cookie 无法获取 CheckAvil= 在浏览器中打开它并打开我得到的源代码后,我得到了很多没有 `CheckAvil= 的信息!看图片 在此处输入图像描述

i'm dealing with HTTPS and i want to get HTTP header for live.com

import urllib2

try:
    email="[email protected]"
    response = urllib2.urlopen("https://signup.live.com/checkavail.aspx?chkavail="+email+"&tk=1258056184535&ru=http%3a%2f%2fmail.live.com%2f%3frru%3dinbox&wa=wsignin1.0&rpsnv=11&ct=1258055283&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1036&id=64855&bk=1258055288&rollrs=12&lic=1")
    print 'response headers: "%s"' % response.info()
except IOError, e:
    if hasattr(e, 'code'): # HTTPError
        print 'http error code: ', e.code
    elif hasattr(e, 'reason'): # URLError
        print "can't connect, reason: ", e.reason
    else:
        raise

so i don't want all the information from headers i just want Set-Cookie information

if you asking what is script do : it's for checking if email avilable to use in hotmail by get the amount from this viralbe CheckAvail=

after edit

thanks for help .. after fixing get only Set-Cookie i got problem it's when i get cookie not get CheckAvil= i got a lot information without `CheckAvil= after open it in browser and open the source i got it !! see the picture enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

成熟的代价 2024-11-23 15:22:34

response.info() 返回的对象是 mimetools.Message (如 urllib2 docs),它是 rfc822.Message,它有一个 getheader() 方法。

因此,您可以执行以下操作:

response = urllib2.urlopen("...")
print response.info().getheader("Set-Cookie") # get the value of the Set-Cookie header

但是,如果您要检查邮件,我建议您使用 POP3 或 IMAP(如果可用)(Python 附带了这两种模块)。

The object returned by response.info() is an instance of mimetools.Message (as described by the urllib2 docs), which is a subclass of rfc822.Message, which has a getheader() method.

So you can do the following:

response = urllib2.urlopen("...")
print response.info().getheader("Set-Cookie") # get the value of the Set-Cookie header

However, if you are checking for mail, I would recommend you to use POP3 or IMAP if available (Python comes with modules for both).

墨洒年华 2024-11-23 15:22:34

这是因为您的 http 响应中包含“Httponly”,这意味着,由于规范的原因,只有 http 连接可以查看。

It's because 'Httponly' in your http response, which meant, because of the specifications, only http connection can view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文