python 爬取学信网登录页面的例子
Python  /  管理员 发布于 7年前   456
我们以学信网为例爬取个人信息
**如果看不清楚
按照以下步骤:**
1.火狐为例 打开需要登录的网页C> F12 开发者模式 (鼠标右击,点击检查元素)C点击网络 C>需要登录的页面登录下C> 点击网络找到 一个POST提交的链接点击C>找到post(注意该post中信息就是我们提交时需要构造的表单信息)
import requestsfrom bs4 import BeautifulSoupfrom http import cookiesimport urllibimport http.cookiejarheaders = { '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 ltlt = 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 爬取学信网登录页面的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号
