在python中获取HTTPS标头
我正在处理 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
response.info()
返回的对象是mimetools.Message
(如urllib2
docs),它是rfc822.Message
,它有一个getheader()
方法。因此,您可以执行以下操作:
但是,如果您要检查邮件,我建议您使用 POP3 或 IMAP(如果可用)(Python 附带了这两种模块)。
The object returned by
response.info()
is an instance ofmimetools.Message
(as described by theurllib2
docs), which is a subclass ofrfc822.Message
, which has agetheader()
method.So you can do the following:
However, if you are checking for mail, I would recommend you to use POP3 or IMAP if available (Python comes with modules for both).
这是因为您的 http 响应中包含“Httponly”,这意味着,由于规范的原因,只有 http 连接可以查看。
It's because 'Httponly' in your http response, which meant, because of the specifications, only http connection can view.