python3 如何登陆https
本文介绍了python3 如何登陆https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
在python3(我用的是python3.5)如何登陆https的网站。
def login(loginurl,logindata):
cj = http.cookiejar.CookieJar()
pro = request.HTTPCookieProcessor(cj)
opener = request.build_opener(pro)
request.install_opener(opener)
req = request.Request(loginurl)
req.add_header('User-Aent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0')
resp = request.urlopen(req, logindata)
# htmlcontent = resp.read().decode('utf-8')
# print(htmlcontent)
login(loginurl,logindata)
用这种方法登陆http是可以获取登陆后的页面的,但是登陆https的网站,在执行该函数后,访问登陆后的页面时,提示无权限访问,未登陆。
怎解?
解决方案
import requests
print requests.get('https://www.baidu.com/', verify=False).content
这篇关于python3 如何登陆https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文