download web page as a pdf using python
by specter - Friday June 23, 2023 at 01:59 PM
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Discord Token Grabber | Private Stealer | Leaked For Free Piplup 356 59,165 2 hours ago
Last Post: StanMaliced
  (E-Book) OSINT Techniques | How To Uncover Information Online Chapo 58 5,439 Yesterday, 08:20 AM
Last Post: demmama
  ❄️HOW TO CREATE COMBOS❄️ F2w 24 3,043 May 01, 2026, 07:27 AM
Last Post: ximmhrss
  Useful links for developers Manfruity 37 2,628 Apr 30, 2026, 02:01 PM
Last Post: seoriz111
  ⭐ Sektor7 - All courses (6 in total) ⭐ red_dot 599 38,966 Apr 23, 2026, 09:51 PM
Last Post: cwel321

Forum Jump:


 Users browsing this forum: 1 Guest(s)