python 길수대학 홈 페이지 성적표

항목 주소:
https://github.com/chen0495/pythonCrawlerForJSU
환경.
python 3.5 즉 이상
  • request、BeautifulSoup、numpy、pandas.
  • BeautifulSoup 설치 명령 pip install BeautifulSoup 4
  • 설정 및 사용
    학교 성적표 조회 사이트 에 접속 하여 쿠키 를 수정 합 니 다.

    F12 를 누 른 후 Ctrl+R 을 누 르 면 새로 고침 하고 쿠키 를 가 져 오 는 방법 은 다음 그림 을 참조 하 십시오.

    파충류 url 을 자신의 성적표 사이트 로 수정 합 니 다.

    src/main.py 파일 을 실행 하면/result 에서 csv 파일 을 얻 을 수 있 습 니 다.
    결과 전시

    전체 코드
    
    # -*- coding: utf-8 -*-
    # @Time    : 5/29/2021 2:13 PM
    # @Author  : Chen0495
    # @Email   : [email protected]|[email protected]
    # @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 이 성적 표를 얻 는 것 에 관 한 자 료 는 우리 의 다른 관련 글 을 주목 하 세 요!

    좋은 웹페이지 즐겨찾기