Download page as pdf in python
by specter - Friday June 16, 2023 at 04:50 AM
#1
import argparse
import pyppdf
import re
from pyppeteer.errors import PageError, TimeoutError, NetworkError


def main():
    parser = argparse.ArgumentParser(description = 'Page Downloader as PDF')
    parser.add_argument('--link', '-l', action = 'store', dest = 'link',
                        required = True, help = 'Inform the link to download.')
    parser.add_argument('--name', '-n', action = 'store', dest = 'name',
                        required = False, help = 'Inform the name to save.')

    arguments = parser.parse_args()

    url = arguments.link

    if not arguments.name:
        name = re.sub(r'^\w+://', '', url.lower())
        name = name.replace('/', '-')
    else:
        name = arguments.name

    if not name.endswith('.pdf'):
        name = name + '.pdf'

    print(f'Name of the file: {name}')

    try:
        pyppdf.save_pdf(name, url)
    except PageError:
        print('URL could not be resolved.')
    except TimeoutError:
        print('Timeout.')
    except NetworkError:
        print('No access to the network.')

if __name__ == '__main__':
    main()
Reply
#2
thank u for sharing this
Reply
#3
Cool , Thanks
Reply
#4
wooh  Idea
Reply
#5
Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to have CHATGPT PERPLEXITY and OTHERS for FREE2. Amsterdamer 36 3,514 May 03, 2026, 05:09 PM
Last Post: arhmel0
  Discord Token Grabber | Private Stealer | Leaked For Free Piplup 359 59,836 May 03, 2026, 04:37 PM
Last Post: kidspam
  How to catch a pedophile slxppv 288 36,436 May 03, 2026, 08:13 AM
Last Post: ilya313
  How to build GTA V from source depodaapre 102 15,252 May 03, 2026, 03:25 AM
Last Post: pihuit38293
  (E-Book) OSINT Techniques | How To Uncover Information Online Chapo 58 5,532 May 02, 2026, 08:20 AM
Last Post: demmama

Forum Jump:


 Users browsing this forum: 1 Guest(s)