700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python编辑器中文字体倒立的_如何用Python+人工识别处理知乎的倒立汉字验证码...

python编辑器中文字体倒立的_如何用Python+人工识别处理知乎的倒立汉字验证码...

时间:2020-08-18 20:50:55

相关推荐

python编辑器中文字体倒立的_如何用Python+人工识别处理知乎的倒立汉字验证码...

展开全部

#登录知乎,通过保存验证图片方式

importurllib.request

importurllib.parse

importtime

importhttp.cookiejar

webUrl="/login/email"#不能写/#signin因为不支持重定向e68a84e8a2ad3231313335323631343130323136353331333363393131

webheader={

#'Accept':'text/html,application/xhtml+xml,*/*',

#'Accept-Language':'zh-CN',

#'User-Agent':'Mozilla/5.0(WindowsNT6.1;WOW64;Trident/7.0;rv:11.0)likeGecko',

'User-Agent':'Mozilla/5.0(Linux;Android6.0;Nexus5Build/MRA58N)AppleWebKit/537.36(KHTML,likeGecko)Chrome/56.0.2924.87MobileSafari/537.36',

#'User-Agent':'Mozilla/5.0(iPod;U;CPUiPhoneOS4_3_3likeMacOSX;en-us)AppleWebKit/533.17.9(KHTML,likeGecko)Version/5.0.2Mobile/8J2Safari/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='/captcha.gif?r=%d&type=login&lang=cn'%(time.time()*1000)

#captcha_url='/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()

withopen(captcha_name,'wb')asf:

f.write(content)

postData['captcha']=input('请输入验证码')

#postData['_xsrf']=get_xsrf()

postData['_xsrf']='fa5ae712244bd4287e37180105fc'

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)

withopen("D:/知乎服务器反馈的内容.txt",mode='w',encoding='utf-8')asdataFile:

dataFile.write(data)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。