python 爬取吉首大學網(wǎng)站成績單
項目地址:
https://github.com/chen0495/pythonCrawlerForJSU
環(huán)境
- python 3.5即以上
- request、BeautifulSoup、numpy、pandas.
- 安裝BeautifulSoup使用命令pip install BeautifulSoup4
配置及使用
登陸學校成績單查詢網(wǎng)站,修改cookie.

按F12后按Ctrl+R刷新一下,獲取cookie的方法見下圖:

修改爬蟲url為自己的成績單網(wǎng)址.

運行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 爬取成績單的資料請關注腳本之家其它相關文章!
相關文章
解決python中顯示圖片的plt.imshow plt.show()內存泄漏問題
這篇文章主要介紹了解決python中顯示圖片的plt.imshow plt.show()內存泄漏問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
Python連接MySQL數(shù)據(jù)庫的四種方法
用?Python?連接到?MySQL?數(shù)據(jù)庫的方法不是很系統(tǒng),實際中有幾種不同的連接方法,而且不是所有的方法都能與不同的操作系統(tǒng)很好地配合,本文涵蓋了四種方法,你可以用它們來連接你的Python應用程序和MySQL,需要的朋友可以參考下2024-08-08
使用Python實現(xiàn)獲取網(wǎng)頁指定內容
在當今互聯(lián)網(wǎng)時代,網(wǎng)頁數(shù)據(jù)抓取是一項非常重要的技能,本文將帶你從零開始學習如何使用Python獲取網(wǎng)頁中的指定內容,希望對大家有所幫助2025-03-03
python實現(xiàn)輸入的數(shù)據(jù)在地圖上生成熱力圖效果
今天小編就為大家分享一篇python實現(xiàn)輸入的數(shù)據(jù)在地圖上生成熱力圖效果,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12
Python密碼學Caesar?Cipher凱撒密碼算法教程
這篇文章主要為大家介紹了Python密碼學Caesar?Cipher凱撒密碼算法教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05

