import requests
import random
from bs4 import BeautifulSoup
import pandas as pd
aqyzUrl = "http://www.aqyz.net/xwzx/mzrc/index.html"
def GetHtmlSoup(url):
Html = requests.get(url, headers={
"User-Agent": "XY"
})
Html.encoding = 'utf-8'
Soup = BeautifulSoup(Html.text, 'lxml')
return Soup
def save_as_csv(csv, filename):
with open(filename, 'a', encoding='utf-8') as file:
file.write(csv)
aqyzContentSoup = GetHtmlSoup(aqyzUrl)
# print(aqyzContentSoup.prettify())
aqyzContentList = aqyzContentSoup.find('ul', 'doc_list').find_all('li')
aqyzContent = aqyzContentList[0]
aqyzContentLatest = aqyzContent.find_next("a")
aqyzContentLatestName = aqyzContentLatest.text.replace("\n", " ")
aqyzContentLatestLink = aqyzContentLatest.get('href')
# print(aqyzContentLatestLink)
# print(aqyzContentLatestName)
aqyzLatestSoup = GetHtmlSoup(aqyzContentLatestLink)
# print(aqyzLatestSoup.prettify())
aqyzLatestdiv1 = aqyzLatestSoup.find('div', 'newscontnet')
aqyzLatestdiv1.encode("utf-8")
aqyzLatestTableHtml = aqyzLatestdiv1.find('table')
# print(aqyzLatestTableHtml)
aqyzLatestTable = pd.read_html(str(aqyzLatestTableHtml))[0]
# print(aqyzLatestTable)
aqyzLatestTableCsv = pd.DataFrame.to_csv(aqyzLatestTable)
save_as_csv(aqyzLatestTableCsv,aqyzContentLatestName+".csv")
import json
# 未完待续
# 忘记addon.json的结构了
import zhixuewang as zwx
print("用户名")
username = input()
print("密码")
password = input()
student = zwx.login_student(username,password)
import pandas as pd