首页 > Python用urllib去请求一个网页出现_ssl.c:590错误?

Python用urllib去请求一个网页出现_ssl.c:590错误?

如图所示,从来没有遇到过这个错误,今天突然遇到了,有知道的朋友吗?

以下是我的代码:

# encoding:utf-8
import urllib, urllib2, re, cookielib,requests
 
# 账号相关参数
username = 'XXXXXX'
password = 'XXXXXX'
# 打开目标链接,获取Html
url = r'https://cas.XXXXXX.edu.cn/cas/login'
text= urllib.urlopen(url)
contents = text.read()
# 获取Lt值
reg = r'name="lt" value="(.*)"/>'
pattern = re.compile(reg)
result = pattern.findall(contents)
Lt = result[0]
# 保存cookie
lgurl = r'https://cas.XXXXX.edu.cn/cas/login'
cookie = cookielib.CookieJar()
cookie_handler = urllib2.HTTPCookieProcessor(cookie)
hdr = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36'}
post_data = {'Lt':Lt, 'username':username, 'password':password}
dt = urllib.urlencode(post_data)
req = urllib2.Request(lgurl, dt, hdr)
opener = urllib2.build_opener(cookie_handler)
urllib2.install_opener(opener)
response = opener.open(req)
page = response.read()
# print(page)
testurl = 'http://jwxt.XXXXXXXX.edu.cn/XXXXXXX/teach/grade/course/person.action'
req = urllib2.urlopen(testurl)
print(req.read())

你导入了requests ,为啥不直接用它了,很方便,cookie都不用自己维护,关于urllib无法打开https,请参考 https://.com/q/1010000002474...

【热门文章】
【热门文章】