gpt4 book ai didi

python 爬取吉首大学网站成绩单

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章python 爬取吉首大学网站成绩单由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

项目地址:

https://github.com/chen0495/pythoncrawlerforjsu 。

环境

  • python 3.5即以上
  • request、beautifulsoup、numpy、pandas.
  • 安装beautifulsoup使用命令pip install beautifulsoup4

配置及使用

登陆学校成绩单查询网站,修改cookie. 。

python 爬取吉首大学网站成绩单

按f12后按ctrl+r刷新一下,获取cookie的方法见下图

python 爬取吉首大学网站成绩单

修改爬虫url为自己的成绩单网址. 。

python 爬取吉首大学网站成绩单

运行src/main.py文件即可在/result下得到csv文件. 。

结果展示

python 爬取吉首大学网站成绩单

完整代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- 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 爬取成绩单的资料请关注我其它相关文章! 。

原文链接:https://github.com/chen0495/pythonCrawlerForJSU 。

最后此篇关于python 爬取吉首大学网站成绩单的文章就讲到这里了,如果你想了解更多关于python 爬取吉首大学网站成绩单的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com