forked from hastagAB/Awesome-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Download page as PDF. * Contributor name. * Pudim page typo.
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Download Page as PDF: | ||
|
||
Download a page as a PDF . | ||
|
||
#### Required Modules : | ||
- pyppdf | ||
```bash | ||
pip3 install pyppdf | ||
``` | ||
- pyppyteer | ||
```bash | ||
pip3 install pyppeteer | ||
``` | ||
|
||
#### Examples of use : | ||
- Download a page: | ||
```bash | ||
python download-page-as-pdf.py -l 'www.pudim.com.br' | ||
``` | ||
|
||
- Download a page and give a pdf name: | ||
```bash | ||
python download-page-as-pdf.py -l 'http://www.pudim.com.br' -n 'pudim.pdf' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/python | ||
# -*- coding: UTF-8 -*- | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pyppdf==0.1.2 | ||
pyppeteer==0.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters