python 爬取学信网登录页面的例子
2019-08-13 15:04
1286 查看
我们以学信网为例爬取个人信息
**如果看不清楚
按照以下步骤:**
1.火狐为例 打开需要登录的网页–> F12 开发者模式 (鼠标右击,点击检查元素)–点击网络 –>需要登录的页面登录下–> 点击网络找到 一个POST提交的链接点击–>找到post(注意该post中信息就是我们提交时需要构造的表单信息)
import requests from bs4 import BeautifulSoup from http import cookies import urllib import http.cookiejar headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0', 'Referer':'https://account.chsi.com.cn/passport/login?service=https://my.chsi.com.cn/archive/j_spring_cas_security_check', } session = requests.Session() session.headers.update(headers) username = 'xxx' password = 'xxx' url = 'https://account.chsi.com.cn/passport/login?service=https://my.chsi.com.cn/archive/j_spring_cas_security_check' def login(username,password,lt,_eventId='submit'): #模拟登入函数 #构造表单数据 data = { #需要传去的数据 '_eventId':_eventId, 'lt':lt, 'password':password, 'submit':u'登录', 'username':username, } html = session.post(url,data=data,headers=headers) def get_lt(url): #解析登入界面_eventId html = session.get(url) #获取 lt soup = BeautifulSoup(html.text,'lxml',from_encoding="utf-8") lt=soup.find('input',type="hidden")['value'] return lt lt = get_lt(url)#获取登录form表单信息 以学信网为例 login(username,password,lt) login_url = 'https://my.chsi.com.cn/archive/gdjy/xj/show.action' per_html = session.get(login_url) soup = BeautifulSoup(per_html.text,'lxml',from_encoding="utf-8") print(soup) for tag in soup.find_all('table',class_='mb-table'): print(tag) for tag1 in tag.find_all('td'): title= tag1.get_text(); print(title)
以上这篇python 爬取学信网登录页面的例子就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- [置顶] python 爬取学信网登录页面
- Python 用户登录验证的小例子
- php使用curl模拟登录后采集页面的例子
- React Native 启动白屏->引导页面->登录页面 例子
- 【三】【selenium+python】账号登录页面并刷新页面
- 在登录页面点击登录之后页面重定向了无数次,如何 用Python 拿到重定向前的 cookie
- Weex例子——登录页面
- php使用curl模拟登录后采集页面的例子
- Python3 Post登录并且保存cookie登录其他页面
- Python3-Selenium3使用PO设计模式(Page Object)实现简单的页面登录操作
- 使用python3 + selenium3 进行个人博客系统登录页面实战
- 如何使用python自动登录路由器且获取页面内容
- Python 爬虫实现简单例子(爬取某个页面)
- Python3 Post登录并且保存cookie登录其他页面的方法
- Python手动构造Cookie模拟登录后获取网站页面内容
- Python爬虫 --登录页面除了Cookie,另外一种进行登录的方式
- 例子:实现最新版本Node.js中Express+mongodb的登录注册页面
- Python爬虫模拟登录失败,重定向到登录页面解决方法。
- selenium+python登录登出百度,等待页面加载,鼠标定位
- 新手详细教程:python3基于SVM识别学校登录页面验证码