Skip to content

Instantly share code, notes, and snippets.

@hankhsu1996
Last active September 24, 2017 06:18
Show Gist options
  • Save hankhsu1996/9a2e25f8c6663658684cd75e0fdd6673 to your computer and use it in GitHub Desktop.
Save hankhsu1996/9a2e25f8c6663658684cd75e0fdd6673 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
def post_to_ntu():
data = {
'current_sem': '106-1',
'cstype': '1',
'csname': '%ACy%C5%E9%A4O%BE%C7',
'alltime': 'yes',
'allproced': 'yes',
'allsel': 'yes',
'page_cnt': '15',
'Submit22': '%ACd%B8%DF'
}
headers = {
'Host': 'nol.ntu.edu.tw',
'Connection': 'keep-alive',
'Content-Length': '123',
'Cache-Control': 'max-age=0',
'Origin': 'https://nol.ntu.edu.tw',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Referer': 'https://nol.ntu.edu.tw/nol/coursesearch/search_result.php',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4',
'Cookie': '_ga=GA1.3.2139797329.1498454069; __utma=154300519.2139797329.1498454069.1504011411.1504015788.3; __utmz=154300519.1504015788.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); locale=zh_TW; ASPSESSIONIDQSSCARDT=JCLDJHBDBBLDKGCFMLAGJJHI; PHPSESSID=mk6kbqguf4i2do0q4d2erphmj3; NOLlang=CH'
}
cookies = {
'ASPSESSIONIDQSSCARDT': 'JCLDJHBDBBLDKGCFMLAGJJHI',
'NOLlang': 'CH',
'PHPSESSID': 'mk6kbqguf4i2do0q4d2erphmj3',
'__utma': '154300519.2139797329.1498454069.1504011411.1504015788.3',
'__utmz': '154300519.1504015788.3.3',
'_ga': 'GA1.3.2139797329.1498454069',
'locale': 'zh_TW'
}
resp = requests.post(NTU_URL, data = data, headers = headers, cookies = cookies)
soup = BeautifulSoup(resp.text, 'html.parser')
return soup
if __name__ == '__main__':
NTU_URL = 'https://nol.ntu.edu.tw/nol/coursesearch/search_result.php'
post_to_ntu()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment