使用python脚本模拟登录知乎
2017-03-02 15:13
656 查看
python登录知乎—无验证码
import requestsfrom bs4 import BeautifulSoup
class ZHIHU():
def __init__(self): self.login_url = 'https://www.zhihu.com/login/phone_num' self.login_data = {'phone_num':'xxxxxxxxxxx', 'password':'xxxxxxxx'} self.headers = {'Host':'www.zhihu.com', 'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} def login_in(self): session = requests.session() response1 = requests.get('https://www.zhihu.com/', headers=self.headers) soup1 = BeautifulSoup(response1.text, 'html.parser') xsrf = soup1.find('input',attrs={'name':'_xsrf'})['value'] self.login_data['_xsrf']=xsrf response2 = session.post(self.login_url, data=self.login_data, headers=self.headers) print(response2.text) return session
zhihu_spider = ZHIHU()
zhihu_spider.login()
登录成功(r=0),输出如下内容:
{“r”:0,
“msg”: “\u767b\u5f55\u6210\u529f”
}
登录失败(r=1),如密码错误时输出如下内容:
{
“r”: 1,
“errcode”: 100005,
"data": {"password":"\u5e10\u53f7\u6216\u5bc6\u7801\u9519\u8bef"}, "msg": "\u5e10\u53f7\u6216\u5bc6\u7801\u9519\u8bef"
}
相关文章推荐
- [Python]网络爬虫(三):使用cookiejar管理cookie 以及 模拟登录知乎
- 【python爬虫03】使用Scrapy框架模拟登录知乎
- 【python爬虫01】使用requests库模拟登录知乎
- 使用Python模拟登录知乎
- 使用Python+Selenium模拟登录QQ空间
- python3下使用scrapy实现模拟用户登录与cookie存储 —— 基础篇(马蜂窝)
- python3模拟登录知乎
- python使用requests模块模拟登陆知乎
- Python 脚本登录知乎
- Python爬虫入门:Urllib库使用详解(模拟CSDN登录)
- python 利用浏览器 Cookie 模拟登录的用户访问知乎
- Python网络爬虫之模拟登录(以知乎为例)
- python---使用pxssh模块模拟ssh登录linux主机
- 知乎改版使用restapi后模拟登录
- Python爬虫之模拟知乎登录的方法教程
- Python爬虫初学(三)—— 模拟登录知乎
- selenium+python关于登录的脚本代码,使用了读取excel以及向excel中写入测试结果的方法
- 使用Python模拟登录QQ邮箱获取QQ好友列表
- python--python3爬虫之模拟登录知乎
- python-知乎模拟登录