# -*- 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模拟知乎登录的更多相关文章

  1. (转)request模拟知乎登录(无验证码机制

    原文:http://www.itnose.net/detail/6755805.html import request try: import cookielib #python2版本 except: ...

  2. request模拟知乎登录(无验证码机制)

    import request try: import cookielib #python2版本 except: import http.cookiejar as cookielib #python3版 ...

  3. 使用selenium模拟知网登录

    之前都是用phantomjs和selenium模拟浏览器动作的,后来phantomjs不再更新,就转用chrome了 本次模拟登录的网站是中国知网http://login.cnki.net/login ...

  4. python爬虫-知乎登录

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' Required - requests (必须) - pillow (可选) ''' import ...

  5. Python 模拟淘宝登录的两种方法

    方法一.urllib的post登录 import urllib import urllib2 import cookielib def taobao(username,password): cj = ...

  6. scrapy模拟知乎登录(无验证码机制)

    ---恢复内容开始--- spiders 文件夹下新建zhihu.py文件(从dos窗口中进入虚拟环境,再进入工程目录之后输入命令 scrapy genspider zhihu www.zhihu.c ...

  7. 新版知乎登录之post请求

    前言 在上一篇文章中给大家讲解了requests发送post请求的几种方式,并分析了一些使用陷阱. 疑惑 在文章发表之后,有朋友给我留言说,知乎登录就没有使用提交Form表单(application/ ...

  8. 【Python数据分析】Python模拟登录(一) requests.Session应用

    最近由于某些原因,需要用到Python模拟登录网站,但是以前对这块并不了解,而且目标网站的登录方法较为复杂, 所以一下卡在这里了,于是我决定从简单的模拟开始,逐渐深入地研究下这块. 注:本文仅为交流学 ...

  9. 【py登陆】python模拟登录

    用Python模拟登录网站 前面简单提到了 Python 模拟登录的程序,但是没写清楚,这里再补上一个带注释的 Python 模拟登录的示例程序.简单说一下流程:先用cookielib获取cookie ...

随机推荐

  1. 分类模型的性能评价指标(Classification Model Performance Evaluation Metric)

    二分类模型的预测结果分为四种情况(正类为1,反类为0): TP(True Positive):预测为正类,且预测正确(真实为1,预测也为1) FP(False Positive):预测为正类,但预测错 ...

  2. CTS&&APIO2019爆零记

    如果你只好奇测试相关请跳至day 2 day 3 day 6 scoi 2019 之后 ​ 由于实力问题,省选的时候排名在三十多,显然是没有进队.不过可能是受过的打击比较多,所以还没有特别颓废,甚至连 ...

  3. TODO list(咕咕咕。。。

    1. Segment Tree Beats 2. ZR集训补题(还剩10题) 3. 尽可能将各种数据结构写得熟练...(某神仙:要把平衡树写得跟线段树一样熟练) 4. 树相关数据结构和算法(dsu o ...

  4. Luogu5206 【WC2019】数树 【容斥,生成函数】

    题目链接 第一问白给. 第二问: 设 \(b=y^{-1}\),且以下的 \(Ans\) 是除去 \(y^n\) 的. 设 \(C(T)\) 是固定了 \(T\) 中的边,再连 \(n-|T|-1\) ...

  5. 原创:搜索排序算法之自定义性能优良的PriorityQueue(与Python的heap比较)

    前几天写了一篇关于"史上对BM25模型最全面最深刻解读以及lucene排序深入解读"的博客,lucene最后排序用到的思想是"从海量数据中寻找topK"的时间空 ...

  6. 【2019.12.11】SDN上机第7次作业

    打开P4的目录,运行主程序 make run 此时输入命令 pingall 会显示所有的网络不通 改为下方代码 /* -*- P4_16 -*- */ #include <core.p4> ...

  7. MySql 三大知识点——索引、锁、事

    作者:莫那鲁道原文:http://thinkinjava.cn/2019/03/16/2019-03-16-mysql/ 1. 索引 索引,类似书籍的目录,可以根据目录的某个页码立即找到对应的内容. ...

  8. Jquery创建动态表单

    $(document).ready(function(){ $("#button1").click(function(){ //获取html <body></bo ...

  9. koa2 get post api restful前端联调

    1.git https://github.com/MengFangui/koa2-restful-api 2.示例代码 //引入 Koa 服务器 const koa = require('koa'); ...

  10. 使用PLSQL导入excel数据至oracle数据库

    https://blog.csdn.net/qq_42909551/article/details/82108754 https://jingyan.baidu.com/album/14bd256e2 ...