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
#6
it can also be done by using other library to like pdfkit and other, this program is also good thanks for share
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [ E-BOOK ] BLACK HAT PYTHON PROGRAMMING mrJ3tt 5 640 02-18-2024, 10:29 AM
Last Post: suzugodess
  Retrieving Firefox Cookies Using Python Aurora 15 5,208 01-23-2024, 06:04 PM
Last Post: ncxcccccc
  [Tutorial] Bruteforce Any RDP Using Python 0x666 10 2,124 01-23-2024, 02:34 PM
Last Post: PMoney
  Python Requests 1.1 - Downtime Checker swag 3 1,959 10-17-2023, 10:44 PM
Last Post: popadonpin
  python script into your website whitenigger 6 2,228 10-12-2023, 12:06 PM
Last Post: whitenigger



 Users browsing this thread: 1 Guest(s)