(转)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 ...
随机推荐
- warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
问题: yum安装软件时候报如下错误: warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOK ...
- ssh 认证
ssh 秘钥认证流程 ssh配置认证 基于口令(密码)的安全验证 [root@m01 ~]# ssh 10.0.0.41 hostname root@10.0.0.41's password: bac ...
- EXCEL中R1C1样式引用
主要引用http://club.excelhome.net/thread-759847-1-1.html Sub chengji() ' ' 宏1 宏 ' Dim Finalrow As Intege ...
- MIT Molecular Biology 笔记4 DNA相关实验
视频 https://www.bilibili.com/video/av7973580?from=search&seid=16993146754254492690 教材 Molecular ...
- linux grep进阶
1.搜寻特定字符串 搜寻特定字符串很简单吧?假设我们要从刚刚的文件当中取得 the 这个特定字符串,最简单的方式就是这样: 那如果想要『反向选择』呢?也就是说,当该行没有 'the' 这个字符串时才显 ...
- POJ3273--Monthly Expense(Binary Search)
Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...
- 6.form表单四种提交方式
一.使用jquery的ajax方式提交: 二.使用easyui的form组件内置的submit方法提交: 三.先定义表单,然后使用submit方法提交: 四.先定义表单,然后按下enter键时提交:
- poj 1837 01背包
Balance Time Limit: 1000 MS Memory Limit: 30000 KB 64-bit integer IO format: %I64d , %I64u Java clas ...
- CxGrid鼠标移到更改颜色
CxGrid鼠标移到更改颜色 设置表单中TcxGrid1DBTableView的Styles属性,设置Selection procedure TForm1.cxGrid1DBTableView1Mou ...
- 在线团队协作工具+在线UML工具
话不多说直接上https://worktile.com去看,顺便附上小众软件上面的介绍 默默增加worktile的外国原版https://trello.com/,worktile照着trello做的, ...