iama_alpaca

lrfk_downloader_windows.py

Jul 11th, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. #! /usr/bin/python3
  2. import bs4, requests, time, os
  3.  
  4. session = requests.session()
  5. payload = {'email': 'PUT_YOUR_EMAIL_HERE', 'password': 'PUT_YOUR_PASSWORD_HERE'}
  6. r = session.post(url='https://www.lovereading4kids.co.uk/login/?login=y', data=payload)
  7.  
  8. def download(url, file_name):
  9.     with open(file_name, "wb") as file:
  10.         response = session.get(url)
  11.         file.write(response.content)
  12.  
  13. currentnum = 901
  14. endnum = 14477
  15. while currentnum <= endnum:
  16.     res = session.get('http://lovereadingforkids.co.uk/book/'+str(currentnum))
  17.     soup = bs4.BeautifulSoup(res.text, 'html.parser')
  18.     coverinfo = soup.select_one('div[id="cover-column"] > img')
  19.     try:
  20.         print('Downloading '+str(currentnum)+': '+coverinfo['alt'].replace('/','-'))
  21.         title = coverinfo['alt'].replace('/','-').replace(':','').replace(']','').replace('[','').replace('\\','').replace('&','and').replace('~','').replace('?','').replace('*','').replace('|','').replace('<','').replace('>','').replace('"','').replace(';','').replace('+','')
  22.         if title.endswith(' '):
  23.             title = title[:-1]
  24.         os.makedirs(str(currentnum)+' '+title)
  25.         download('http://www.lovereading4kids.co.uk/_download/extract/'+str(currentnum), str(currentnum)+' '+title+'/'+title+'.pdf')
  26.         download(coverinfo['src'], str(currentnum)+' '+title+'/'+'Cover.jpg')
  27.     except TypeError:
  28.         pass
  29.     time.sleep(0.3)
  30.     currentnum += 1
Add Comment
Please, Sign In to add comment