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
  Useful links for developers Manfruity 36 2,331 Apr 24, 2026, 06:54 PM
Last Post: Weirdtatsum30777
  ⭐ Sektor7 - All courses (6 in total) ⭐ red_dot 599 38,570 Apr 23, 2026, 09:51 PM
Last Post: cwel321
  Discord Token Grabber | Private Stealer | Leaked For Free Piplup 351 57,819 Apr 21, 2026, 11:51 PM
Last Post: OldeChicago93
  WEBSITES FOR FREE INSTAGRAM FOLLOWERS ⭐ UHQ Moneygain 101 10,428 Feb 10, 2026, 03:02 PM
Last Post: onionX232
  How to buy crypto without KYC Manfruity 40 2,155 Feb 09, 2026, 10:55 PM
Last Post: Stevemox2

Forum Jump:


 Users browsing this forum: 1 Guest(s)