python3 模拟登录v2ex实例讲解

下面小编就为大家带来一篇python3 模拟登录v2ex实例讲解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

闲的无聊。。。

网上一堆,正好练手(主要是新手)

# coding=utf-8 import requests from bs4 import BeautifulSoup headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', 'origin': 'https://www.v2ex.com', 'referer': 'https://www.v2ex.com/signin', 'host': 'www.v2ex.com', } s = requests.Session() r = s.get('https://www.v2ex.com/signin', headers=headers) soup = BeautifulSoup(r.content, "html.parser") #获取登录数据 once = soup.find('input', {'name': 'once'})['value'] name = soup.find('input', {'type': 'text', 'class': 'sl'})['name'] password = soup.find('input', {'type': 'password', 'class': 'sl'})['name'] login_data = { name : 'xxx', password : 'xxx', 'once' : once, 'next' : '/' } #登录 s.post('https://www.v2ex.com/signin', login_data, headers=headers)

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...