Python 官方文档:入门教程 => 点击学习
目录项目地址:环境配置及使用结果展示完整代码项目地址: https://GitHub.com/chen0495/pythonCrawlerForjsU 环境 Python 3.5即以上 reque
https://GitHub.com/chen0495/pythonCrawlerForjsU
登陆学校成绩单查询网站,修改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: PyCharm
import requests as rq
from bs4 import BeautifulSoup as BS
import numpy as np
import pandas as pd
rq.adapters.DEFAULT_RETRIES = 5
s = 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_vpn_ticketwebvpn_jsu_edu_cn=xxxxxxxxxx; show_vpn=1; refresh=1'
}
# 请更改url
r = rq.get('Https://webvpn.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 = 0
for 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+=1
context = np.delete(context,0,axis=0)
data = pd.DataFrame(context,columns=head)
print(data)
# 生成文件,亲更改文件名
data.to_csv('../result/result.csv',encoding='utf-8-sig')
以上就是python 爬取吉首大学成绩单的详细内容,更多关于python 爬取成绩单的资料请关注编程网其它相关文章!
--结束END--
本文标题: python 爬取吉首大学网站成绩单
本文链接: https://lsjlt.com/news/10829.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0