python 爬取吉首大學(xué)網(wǎng)站成績(jī)單
https://github.com/chen0495/pythonCrawlerForJSU
環(huán)境 python 3.5即以上 request、BeautifulSoup、numpy、pandas. 安裝BeautifulSoup使用命令pip install BeautifulSoup4配置及使用登陸學(xué)校成績(jī)單查詢(xún)網(wǎng)站,修改cookie.
按F12后按Ctrl+R刷新一下,獲取cookie的方法見(jiàn)下圖:
修改爬蟲(chóng)url為自己的成績(jī)單網(wǎng)址.
運(yùn)行src/main.py文件即可在/result下得到csv文件.
結(jié)果展示# -*- 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 # 關(guān)閉多余連接header = { # 請(qǐng)更改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’}# 請(qǐng)更改urlr = 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(’序號(hào)’)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 = pd.DataFrame(context,columns=head)print(data)# 生成文件,親更改文件名data.to_csv(’../result/result.csv’,encoding=’utf-8-sig’)
以上就是python 爬取吉首大學(xué)成績(jī)單的詳細(xì)內(nèi)容,更多關(guān)于python 爬取成績(jī)單的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. SSM框架JSP使用Layui實(shí)現(xiàn)layer彈出層效果2. IntelliJ IDEA導(dǎo)入jar包的方法3. 刪除docker里建立容器的操作方法4. IntelliJ IDEA導(dǎo)出項(xiàng)目的方法5. java使用xfire搭建webservice服務(wù)的過(guò)程詳解6. .Net中的Http請(qǐng)求調(diào)用詳解(Post與Get)7. JS如何在數(shù)組指定位置插入元素8. 解決IDEA項(xiàng)目project包目錄消失的問(wèn)題9. 如果你恨一個(gè)程序員,忽悠他去做iOS開(kāi)發(fā)10. Java源碼解析之ClassLoader
