(转)request模拟知乎登录(无验证码机制
原文:http://www.itnose.net/detail/6755805.html
import request
try:
import cookielib #python2版本
except:
import http.cookiejar as cookielib #python3版本
import re
import
session=request.session()
session.cookies=cookielib.LWPCookieJar(filename="cookies.txt") #将cookies存储到本地文件
#加载cookies文件
try:
session.cookies.load(ignore_discard=True)
except:
print("cookies未能加载")
User_Agent="Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
header={
"HOST" : "www.zhihu.com",
"Referer" : "https://www.zhihu.com",
"User_Agent" : User_Agen"
}
#获取xsrf
def get_xsrf():
response=session.post("https://www.zhihu.com",headers=header) #请求网页需带上头文件
match_obj=re.match(' .*name="_xsrf" value="(.*?)" ') #注意使用单双引号
if match_obj:
return (match_obj(1))
else:
return " "
def get_index():
response=session.get("https://www.zhihu.com",headers=header)
with open("index_page.heml",wb) as f:
f,write(response.text.encode("utf-8"))
print ("ok")
#模拟知乎登录
def zhihu_login(account,password):
if re.match("^1\d{10}",account): #验证账号是否为手机号
print ("手机登录")
post_url="https://www.zhihu.com/login/phone_num"
post_data={
"_xsrf" : get_xsrf(),
"phone_num" : account,
"password" : password
}
else:
if "@" in account:
print (“邮箱登录”)
post_url="https://www.zhihu.com/login/email"
post_data={
"_xsrf" : get_xsrf(),
"email" : account,
"password" : password
}
response_text=session.post(post_url,post_data,headers=header)
session.cookies.save()
#验证是否登录成功
def is_login():
inbox_url="https://www.zhihu.com/inbox"
response=session.get(inbox_url,headers=header,allow_redirects=False)
if response.status_code !=200:
return False
else:
return True
zhihu.login("18782902568","admin123")
get_index()
(转)request模拟知乎登录(无验证码机制的更多相关文章
- scrapy模拟知乎登录(无验证码机制)
---恢复内容开始--- spiders 文件夹下新建zhihu.py文件(从dos窗口中进入虚拟环境,再进入工程目录之后输入命令 scrapy genspider zhihu www.zhihu.c ...
- request模拟知乎登录(无验证码机制)
import request try: import cookielib #python2版本 except: import http.cookiejar as cookielib #python3版 ...
- htmlunit 模拟登录 无验证码
1.模拟登录csdn,最开始的时候使用的是httpclient,网上的所有模拟登录csdn的版本都是找到lt/execution/event_id.连同用户名及密码 一起发送即可,但是目前的csdn的 ...
- 使用selenium模拟知网登录
之前都是用phantomjs和selenium模拟浏览器动作的,后来phantomjs不再更新,就转用chrome了 本次模拟登录的网站是中国知网http://login.cnki.net/login ...
- Python模拟知乎登录
# -*- coding:utf-8 -*- import urllib import urllib2 import cookielib import time from PIL import Ima ...
- 8-python模拟登入(无验证码)
方式: 1.手动登入,获取cookie 2.使用cookielib库 和 HTTPCookieProcessor处理器 #_*_ coding: utf-8 _*_ ''' Created on 20 ...
- 新版知乎登录之post请求
前言 在上一篇文章中给大家讲解了requests发送post请求的几种方式,并分析了一些使用陷阱. 疑惑 在文章发表之后,有朋友给我留言说,知乎登录就没有使用提交Form表单(application/ ...
- python爬虫scrapy框架——人工识别知乎登录知乎倒立文字验证码和数字英文验证码
目前知乎使用了点击图中倒立文字的验证码: 用户需要点击图中倒立的文字才能登录. 这个给爬虫带来了一定难度,但并非无法解决,经过一天的耐心查询,终于可以人工识别验证码并达到登录成功状态,下文将和大家一一 ...
- 第三百四十三节,Python分布式爬虫打造搜索引擎Scrapy精讲—scrapy模拟登陆和知乎倒立文字验证码识别
第三百四十三节,Python分布式爬虫打造搜索引擎Scrapy精讲—scrapy模拟登陆和知乎倒立文字验证码识别 第一步.首先下载,大神者也的倒立文字验证码识别程序 下载地址:https://gith ...
随机推荐
- JAVA技术路线2
https://www.zhihu.com/question/56110328 1.JavaSE学习视频 http://pan.baidu.com/s/1bp3g6rd2.javaweb的学习视频 h ...
- centos 7 安装 python3.6 python3 安装步骤以及pip pip3安装挂载
首先去python官网下载python3的源码包,网址:https://www.python.org/ 或者直接wget下载 wget https://www.python.org/ftp/pytho ...
- 15-BOM
BOM的介绍 JavaScript基础分为三个部分: ECMAScript:JavaScript的语法标准.包括变量.表达式.运算符.函数.if语句.for语句等. DOM:文档对象模型,操作网页上的 ...
- x11 VNC远程桌面
Ubuntu远程桌面,类似于qq远程桌面(Ubuntu没有内置桌面系统吗?) $ sudo apt-get update $ sudo apt-get install x11vnc $ x11vnc ...
- eclipse选中某个字段没法高亮其他相同字段
eclipse选中某个字段无法高亮其他相同字段解决办法: window >> preference >> java >> Editor >> Mark ...
- bootstrap增删改查
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...
- 封装了三个对TMemoryStream操作的函数,大牛莫笑
// TMemoryStream 转化为string字符串 function MemoryStreamToString(M: TMemoryStream): AnsiString; begin Set ...
- 针对 easyui boolean 布尔值 的处理
1.html代码 <select class="easyui-combobox" data-options="editable:false,panelHeight: ...
- 纸壳CMS主题增强,支持主题中加入模板
背景 在之前,纸壳CMS的主题仅仅只是CSS样式,并不支持在主题下使用模板来构建不同的HTML结构.现在我们对主题功能做了增强,可以在主题下添加各自的模板,这样在制作主题时,就会更加自由.不仅如此,新 ...
- UWP 使用Windows Community Toolkit 的OneDrive service上传下载文件
上一年年底写过两篇文章 UWP 使用OneDrive云存储2.x api(一)[全网首发] UWP 使用OneDrive云存储2.x api(二)[全网首发] 没想到半年之后,VS编译提示方法已经过时 ...