Created
October 5, 2021 15:24
-
-
Save thisiskeanyvy/4293a0baac7bc5c98ff4268fa3177de6 to your computer and use it in GitHub Desktop.
Download Books
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, requests, os | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
if not os.path.exists("livre"): | |
os.makedirs("livre") | |
with open("pages.json") as file: | |
tab = json.loads(file.read()) | |
for i in range(len(tab)): | |
html = tab[i]["html_url"] | |
css = tab[i]["css_url"] | |
mid = tab[i]["id"] | |
gethtml = requests.get(html) | |
#getcss = requests.get(css) | |
nametup = "page-",str(i),"_",mid,".html" | |
name = ''.join(nametup) | |
with open('livre/'+name, 'a+') as newfile: | |
#csscontent = '<style type="text/css">\n',getcss.content.decode("utf-8"),'\n</style>' | |
newfile.write('<!DOCTYPE html><html lang="fr"><head><title>Libmanbuels.fr - Page '+str(i)+'</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><link rel="stylesheet" href="'+css+'"></head><body>'+gethtml.content.decode("utf-8")+'</body></html>') | |
#newfile.write(''.join(csscontent)) | |
newfile.close() | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment