Python模拟登陆 —— 征服验证码 10 知乎(倒立文字验证码)

简介: 知乎的倒立文字验证码# 登录知乎,通过保存验证图片方式import urllib.requestimport urllib.parseimport timeimport http.
img_3902732c31d88d47662709e66271d375.png
知乎的倒立文字验证码
# 登录知乎,通过保存验证图片方式
import urllib.request
import urllib.parse
import time
import http.cookiejar

webUrl = "https://www.zhihu.com/login/email"#不能写https://www.zhihu.com/#signin因为不支持重定向

webheader = {
    # 'Accept': 'text/html, application/xhtml+xml, */*',
    # 'Accept-Language': 'zh-CN',
    # 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko',
    'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36',
    # 'User-Agent': 'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5',
    # 'DNT': '1',
    # 'Connection': 'Keep-Alive'
    }
    
postData = {
    'email': '在这里写你的账号',
    'captcha_type': 'cn',
    'password': '在这里写你的密码',
    '_xsrf': '',
    'captcha': ''
}
localStorePath = "写你想保存的验证码图片的地址"

if __name__ == '__main__':
    #声明一个CookieJar对象实例来保存cookie
    cookie = http.cookiejar.CookieJar()
    #创建opener
    handler = urllib.request.HTTPCookieProcessor(cookie)
    opener = urllib.request.build_opener(handler)#建立opener对象,并添加头信息
    urllib.request.install_opener(opener) 
    
    captcha_url = 'https://www.zhihu.com/captcha.gif?r=%d&type=login&lang=cn' % (time.time() * 1000)
    # captcha_url = 'http://www.zhihu.com/captcha.gif?r=%d&type=login' % (time.time() * 1000)#这样获得的是“字母+数字验证码”

    #这个获取验证码图片的方法是不行的!
    # urllib.request.urlretrieve(captcha_url, localStorePath + 'myCaptcha.gif')
    
    #用urlopen函数保存验证图片
    req = urllib.request.Request(url=captcha_url,headers=webheader)
    content = urllib.request.urlopen(req)
    # content = opener.open(req)
    captcha_name = 'D:/Python学习/crawler_learning/知乎登录专题研究/知乎验证码图片/myNewCaptcha.gif'
    content = content.read()
    with open(captcha_name, 'wb') as f:
        f.write(content)
    
    postData['captcha'] = input('请输入验证码')
    # postData['_xsrf'] = get_xsrf()
    postData['_xsrf'] = 'fa5ae712244bd4287e371801052003fc'
    print(postData['_xsrf'])
    
    #用urlopen函数传送数据给服务器实现登录
    postData_encoded = urllib.parse.urlencode(postData).encode('utf-8')
    req = urllib.request.Request(url=webUrl,data=postData_encoded,headers=webheader)
    webPage = urllib.request.urlopen(req)
    # webPage = opener.open(req)
    data = webPage.read().decode('utf-8')
    
    print(data)
    with open("D:/知乎服务器反馈的内容.txt",mode='w',encoding='utf-8') as dataFile:
        dataFile.write(data)

参考:
http://blog.csdn.net/hudeyu777/article/details/76706007
http://www.jianshu.com/p/50c5815bb60b#

目录
相关文章
|
1月前
|
数据采集 机器学习/深度学习 安全
Python爬虫之极验滑动验证码的识别
了解极验滑动验证码、特点、识别思路、初始化、模拟点击、识别缺口、模拟拖动。
59 0
|
1月前
|
文字识别 数据挖掘 网络安全
Python实现avif图片转jpg格式并识别图片中的文字
在做数据分析的时候有些数据是从图片上去获取的,这就需要去识别图片上的文字。Python有很多库可以很方便的实现OCR识别图片中的文字。这里介绍用EasyOCR库进行图片文字识别。easyocr是一个比较流行的库,支持超过80种语言,识别率高,速度也比较快。
25 2
|
1月前
|
数据采集 Web App开发 文字识别
Python爬虫之点触验证码的识别
点触验证码识别思路,初始化,获取,识别。
55 0
Python爬虫之点触验证码的识别
|
1月前
|
数据采集 文字识别 开发者
Python爬虫之图形验证码的识别
python爬虫逆向图形验证码分析,处理和测试实战。
46 0
|
1月前
|
机器学习/深度学习 人工智能 文字识别
Python常用验证码标注和识别(需求分析和实现思路)
Python常用验证码标注和识别(需求分析和实现思路)
41 0
|
1月前
|
机器学习/深度学习 文字识别 数据安全/隐私保护
Python实现从PDF和图片提取文字的方法总结
Python实现从PDF和图片提取文字的方法总结
43 0
|
1月前
|
数据挖掘 数据安全/隐私保护 开发者
使用Spire.PDF for Python插件从PDF文件提取文字和图片信息
使用Spire.PDF for Python插件从PDF文件提取文字和图片信息
62 0
|
1月前
|
人工智能 开发工具 git
第一次运行 Python 项目,使用 python-pptx 提取 ppt 中的文字和图片
人工智能时代,最需要学习的编程语言是:python 。笔者是个 python 小白,昨天花了两个小时,第一次成功运行起来 python 项目 。 项目是 powerpoint-extractor ,可以将 ppt 文件中的图片提取出来,并输出到固定的目录。
第一次运行 Python 项目,使用 python-pptx 提取 ppt 中的文字和图片
python小玩意——使用PIL模块将文本文字放在图片里面
python小玩意——使用PIL模块将文本文字放在图片里面
python小玩意——使用PIL模块将文本文字放在图片里面
|
Python Windows
使用python生成文字图片,画圆圈 ,生成圆形图片
使用python生成文字图片,画圆圈 ,生成圆形图片
534 0
使用python生成文字图片,画圆圈 ,生成圆形图片