Skip to content

Instantly share code, notes, and snippets.

@tomy0000000
Created November 8, 2017 07:04
Show Gist options
  • Select an option

  • Save tomy0000000/05c6ab312bd1c3d19819a68dc497d3da to your computer and use it in GitHub Desktop.

Select an option

Save tomy0000000/05c6ab312bd1c3d19819a68dc497d3da to your computer and use it in GitHub Desktop.
Grab School Datas from UAC
import requests
import json
import bs4
import re
link_List = input().split(" ")
link_List
Res = []
for each in link_List:
item_link = each
item_Page = requests.get(item_link)
item_Page.encoding = "big5"
item_Soup = bs4.BeautifulSoup(item_Page.text, "lxml")
Item = item_Soup.title.string.split(" - ")
Item.append("")
Infos = list(item_Soup.find_all("td")[2].strings)
for each in range(len(Infos)):
Infos[each] = Infos[each].replace("\xa0","").replace("\u3000","").replace("\n","")
Infos.pop()
for sub in ["國文","英文","數學甲","數學乙","物理","化學"]:
Added = False
for info in Infos:
if sub in info:
Item.append(info[info.find("x")+2:])
Added = True
if Added == False:
Item.append("0")
Item.append(item_Soup.find_all("td")[4].string.replace("\n","").replace("\u3000","").replace(" ",""))
Item.append(item_Soup.find_all("td")[7].string.replace("\n","").replace("\u3000","").replace(" ",""))
Item.append(item_Soup.find_all("td")[10].string.replace("\n","").replace("\u3000","").replace(" ",""))
Item.append("")
Item.append("")
Item.append("")
if item_Soup.find_all("td")[1].string == "\n---":
Item.append("-")
else:
if item_Soup.find_all("td")[1].string is None:
Temp = list(item_Soup.find_all("td")[1].strings)
for sub in range(len(Temp)):
Temp[sub] = Temp[sub].replace("\n","").replace("\u3000","").replace("\xa0","")
Temp.pop()
Item.append("ReTURN".join(Temp))
else:
Item.append(item_Soup.find_all("td")[1].string.replace("\n","").replace("\u3000","").replace(" ",""))
if item_Soup.find_all("td")[8].string == "---":
Item.append("-")
else:
Item.append(item_Soup.find_all("td")[8].string.replace("\n","").replace("\u3000","").replace(" ",""))
Res.append("\t".join(Item))
for each in range(len(Res)):
print(Res[each])
with open("Results.txt","w") as f:
f.write("\n".join(Res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment