Python模拟知乎登录
# -*- coding:utf-8 -*-
import urllib
import urllib2
import cookielib
import time
from PIL import Image cookie = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
url = 'https://www.zhihu.com'
post_url = 'https://www.zhihu.com/login/phone_num'
agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
respose = urllib2.urlopen(url) #获取验证码并存储
def saveImg():
t = str(int(time.time() * 1000))
captcha_url = 'https://www.zhihu.com/captcha.gif?r=' + t + "&type=login&lang=cn"
captcha = urllib2.urlopen(captcha_url)
data =captcha.read()
with open('captcha.gif', 'wb') as f:
f.write(data)
img = Image.open('captcha.gif')
img.show() #获取验证码中倒立文字的位置
def getPoints(n):
switch = {'1':[20.375,22],'2':[45.375,23],'3':[70.375,21],'4':[95.375,20],'5':[120.375,18],'6':[145.375,29],'7':[170.375,17]}
ls = []
for i in list(n):
ls.append(switch[i])
return ls saveImg()
num = raw_input('请输入验证码:')
ls_points = str(getPoints(num))
#获取_xsrf
for item in cookie:
if item.name == '_xsrf':
_xsrf = item.value
headers = {
'User-Agent':agent,
'Referer':'https://www.zhihu.com/',
'X-Xsrftoken':_xsrf
}
postdata = {
'_xsrf': _xsrf,
'password': '******',
'captcha': '{"img_size":[200,44],"input_points":'+ls_points+'}',
'captcha_type': 'cn',
'phone_num': '******'
}
data = urllib.urlencode(postdata)
request = urllib2.Request(post_url, data, headers)
result = urllib2.urlopen(request)
print result.read()
Python模拟知乎登录的更多相关文章
- (转)request模拟知乎登录(无验证码机制
原文:http://www.itnose.net/detail/6755805.html import request try: import cookielib #python2版本 except: ...
- request模拟知乎登录(无验证码机制)
import request try: import cookielib #python2版本 except: import http.cookiejar as cookielib #python3版 ...
- 使用selenium模拟知网登录
之前都是用phantomjs和selenium模拟浏览器动作的,后来phantomjs不再更新,就转用chrome了 本次模拟登录的网站是中国知网http://login.cnki.net/login ...
- python爬虫-知乎登录
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' Required - requests (必须) - pillow (可选) ''' import ...
- Python 模拟淘宝登录的两种方法
方法一.urllib的post登录 import urllib import urllib2 import cookielib def taobao(username,password): cj = ...
- scrapy模拟知乎登录(无验证码机制)
---恢复内容开始--- spiders 文件夹下新建zhihu.py文件(从dos窗口中进入虚拟环境,再进入工程目录之后输入命令 scrapy genspider zhihu www.zhihu.c ...
- 新版知乎登录之post请求
前言 在上一篇文章中给大家讲解了requests发送post请求的几种方式,并分析了一些使用陷阱. 疑惑 在文章发表之后,有朋友给我留言说,知乎登录就没有使用提交Form表单(application/ ...
- 【Python数据分析】Python模拟登录(一) requests.Session应用
最近由于某些原因,需要用到Python模拟登录网站,但是以前对这块并不了解,而且目标网站的登录方法较为复杂, 所以一下卡在这里了,于是我决定从简单的模拟开始,逐渐深入地研究下这块. 注:本文仅为交流学 ...
- 【py登陆】python模拟登录
用Python模拟登录网站 前面简单提到了 Python 模拟登录的程序,但是没写清楚,这里再补上一个带注释的 Python 模拟登录的示例程序.简单说一下流程:先用cookielib获取cookie ...
随机推荐
- pdf 翻译
某某狗 https://www.fanyigou.com/tslg/share/4DO875ON.htm
- arcgis python 获得硬件id
import time import wmi, zlib def get_cpu_info(): tmpdict = {} tmpdict["CpuCores"] = 0 c = ...
- mysql索引原理及优化(二)
索引原理分析:数据结构 索引是最常见的慢查询优化方式其是一种优化查询的数据结构,MySql中的索引是用B+树实现,而B+树就是一种数据结构,可以优化查询速度,可以利用索引快速查找数据,优化查询. 可以 ...
- 三层架构BLL+DAL+Model & MVC & MVVM
三层架构 - 国内版 Binghttps://cn.bing.com/search?FORM=U227DF&PC=U227&q=%E4%B8%89%E5%B1%82%E6%9E%B6% ...
- linux shell中如何批量添加一行内容到某些文件的末尾?
答:先使用find找出要指定的某些文件,然后使用xargs和sed工具将内容插入到这些文件的末尾 find . -name 'filename*' | xargs sed -i '$a\added-c ...
- ios开发 需要注意的地方、注意事项
/* 一.LaunchScreenLaunchScreen产生原因:代替之前的启动图片好处:1.可以展示更多的东西2.可以只需要出一个尺寸的图片. 启动图片的优先级启动图片 < LaunchSc ...
- LeetCode_434. Number of Segments in a String
434. Number of Segments in a String Easy Count the number of segments in a string, where a segment i ...
- -bash: /usr/bin/rm: 参数列表过长
解决方法: find ./ -type f -name "*.nasl"|xargs rm -f find ./ -type f -name "*.*"|xar ...
- 深入理解-CLI与PHP-FPM
原文地址:https://blog.csdn.net/lzx_victory/article/details/85917161 PHP-FPM模式相对于CLI比较复杂,因为PHP-FPM为常驻进程不断 ...
- 【视频开发】Nvidia硬解码总结
Nvidia硬解码总结 1.前言 本文的主要目的是对近期进行的nvidia硬件解码工作的记录和总结.至于为什么研究nvidia硬件解码的具体内容,其实主要是为了在项目中能够利用nvidia的硬件解码和 ...