python|python 爬取吉首大学网站成绩单
目录
- 项目地址:
- 环境
- 配置及使用
- 结果展示
- 完整代码
项目地址: https://github.com/chen0495/pythonCrawlerForJSU
环境
- python 3.5即以上
- request、BeautifulSoup、numpy、pandas.
- 安装BeautifulSoup使用命令pip install BeautifulSoup4
配置及使用
登陆学校成绩单查询网站,修改cookie.
文章图片
按F12后按Ctrl+R刷新一下,获取cookie的方法见下图:
文章图片
修改爬虫url为自己的成绩单网址.
文章图片
运行src/main.py文件即可在/result下得到csv文件.
结果展示
文章图片
完整代码
# -*- coding: utf-8 -*-# @Time: 5/29/2021 2:13 PM# @Author: Chen0495# @Email: 1346565673@qq.com|chenweiin612@gmail.com# @File: main.py# @Software: PyCharmimport requests as rqfrom bs4 import BeautifulSoup as BSimport numpy as npimport pandas as pdrq.adapters.DEFAULT_RETRIES = 5s = rq.session()s.keep_alive = False # 关闭多余连接header = { # 请更改cookie'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4501.0 Safari/537.36 Edg/92.0.891.1','cookie' : 'wengine__ticketweb_jsu_edu_cn=xxxxxxxxxx; show_=1; refresh=1'}# 请更改urlr = rq.get('https://web.jsu.edu.cn/https/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/jsxsd/kscj/cjcx_list', headers = header, verify=False)soup = BS(r.text,'html.parser')head = []for th in soup.find_all("th"):head.append(th.text)while '' in head:head.remove('')head.remove('序号')context = np.array(head)x = []flag = 0for td in soup.find_all("td"):if flag!=0 and flag%11!=1:x.append(td.text)if flag%11==0 and flag!=0:context = np.row_stack((context,np.array(x)))x.clear()flag+=1context = np.delete(context,0,axis=0)data = https://www.it610.com/article/pd.DataFrame(context,columns=head)print(data)# 生成文件,亲更改文件名data.to_csv('../result/result.csv',encoding='utf-8-sig')
以上就是python 爬取吉首大学成绩单的详细内容,更多关于python 爬取成绩单的资料请关注脚本之家其它相关文章!
推荐阅读
- python学习之|python学习之 实现QQ自动发送消息
- 逻辑回归的理解与python示例
- python自定义封装带颜色的logging模块
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum
- Python基础|Python基础 - 练习1
- Python爬虫|Python爬虫 --- 1.4 正则表达式(re库)
- 使用协程爬取网页,计算网页数据大小
- Python(pathlib模块)
- python青少年编程比赛_第十一届蓝桥杯大赛青少年创意编程组比赛细则
- Python数据分析(一)(Matplotlib使用)