Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrazione sfoglialibri hoepli #80

Open
sefirothmorpheus opened this issue Apr 12, 2024 · 2 comments
Open

integrazione sfoglialibri hoepli #80

sefirothmorpheus opened this issue Apr 12, 2024 · 2 comments

Comments

@sefirothmorpheus
Copy link

per qualche periodo, sarà possibile visualizzare in anteprima i libri completi di alcune novità per il 2024
nel seguente link un esempio:

https://copertine.hoepli.it/hoepliscuola/1548-Lughezzani_Clippy_Cloud_Plus_Programmazione/index.html

è possibile modificare il tool in modo che scarichi il libro dall'anteprima hoepli?

@lordsheeva
Copy link

lordsheeva commented Apr 17, 2024

import requests
import re
import fitz

def download_pdf_from_url(url, cookies):
    # richiesta da cookie
    response = requests.get(url, cookies=cookies)

    # esito richiesta
    if response.status_code == 200:
        # se sì scarica pdf
        with open("output.pdf", "wb") as file:
            file.write(response.content)
        print("Download completato")

        # pagine pdf
        pdf = fitz.open("output.pdf")
        num_pages = len(pdf)
        print(f"Il PDF contiene {num_pages} pagine")

        return True
    else:
        print(f"Errore PDF: {response.status_code}")
        return False

# URL PDF
pdf_url = "https://copertine.hoepli.it/hoepliscuola/1548-Lughezzani_Clippy_Cloud_Plus_Programmazione/index.html"

# Cookie con il token di autenticazione
cookies = {
    "_gcl_aw": "xyz"
}

# Scarica il PDF by url && token && cookie
success = download_pdf_from_url(pdf_url, cookies)
if success:
    print("Il download del PDF è riuscito.")
else:
    print("Errore durante il download del PDF.")

@sefirothmorpheus
Copy link
Author

import requests import re import fitz

def download_pdf_from_url(url, cookies): # richiesta da cookie response = requests.get(url, cookies=cookies)

# esito richiesta
if response.status_code == 200:
    # se sì scarica pdf
    with open("output.pdf", "wb") as file:
        file.write(response.content)
    print("Download completato")

    # pagine pdf
    pdf = fitz.open("output.pdf")
    num_pages = len(pdf)
    print(f"Il PDF contiene {num_pages} pagine")

    return True
else:
    print(f"Errore PDF: {response.status_code}")
    return False

URL PDF

pdf_url = "https://copertine.hoepli.it/hoepliscuola/1548-Lughezzani_Clippy_Cloud_Plus_Programmazione/index.html"

Cookie con il token di autenticazione

cookies = { "_gcl_aw": "xyz" }

Scarica il PDF by url && token && cookie

success = download_pdf_from_url(pdf_url, cookies)

if success:
print("Il download del PDF è riuscito.")
else:
print("Errore durante il download del PDF.")

grazie, ma non c'ho capito nulla... potresti spiegarmi passo per passo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants