python爬https_爬虫爬https站点怎么处理的?

一段模拟登入知乎的问题

PS:这里不讨论验证码问题,我的账号登入没有提示验证码

代码信息:

# /usr/bin/python

#coding:utf-8

__author__ = 'eyu Fanne'

import requests,time

from bs4 import BeautifulSoup

begintime = time.time()

headers={

"Host":"www.zhihu.com",

"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",

"Accept":"*/*",

"Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",

"Accept-Encoding":"gzip, deflate",

"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",

"X-Requested-With":"XMLHttpRequest",

"Connection":"keep-alive"

}

login_url=r'https://www.zhihu.com/login/email'

html_txt = requests.get(login_url,verify=False).text

html_soup = BeautifulSoup(html_txt,'lxml')

xsrf = html_soup.find("input",{"name":"_xsrf"})['value']

#print xsrf

#print html_txt

s = requests.session()

url_data={

"_xsrf":xsrf,

"email":"******",

"password":"********",

'remember_me':'true'

}

s_login=s.post(login_url,data=url_data,headers=headers,verify=False)

print s_login.text

endtime = time.time()

usetime = endtime - begintime

print "执行脚本总用时 %s 秒" % usetime

#print s.get('https://www.zhihu.com',verify=False).text

执行结果:

C:\Python27_x86\lib\site-packages\requests\packages\urllib3\connectionpool.py:768: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html

InsecureRequestWarning)

C:\Python27_x86\lib\site-packages\requests\packages\urllib3\connectionpool.py:768: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html

InsecureRequestWarning)

C:\Python27_x86\lib\site-packages\requests\packages\urllib3\connectionpool.py:768: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html

InsecureRequestWarning)

{"r":0,

"msg": "\u767b\u9646\u6210\u529f"

}

执行脚本总用时 73.2650001049 秒

在模拟登入的时候,不知道是不是因为https的问题处理的好慢,整个模拟登入要73s才完成,不知卡在哪里了。

像类似这种问题的应该怎么处理。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值