mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Download page as pdf (#196)
* Download page as PDF. * Contributor name. * Pudim page typo.
This commit is contained in:
parent
21b89e112a
commit
957f7ab45c
24
Download-page-as-pdf/README.md
Normal file
24
Download-page-as-pdf/README.md
Normal file
|
@ -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'
|
||||
```
|
42
Download-page-as-pdf/download-page-as-pdf.py
Normal file
42
Download-page-as-pdf/download-page-as-pdf.py
Normal file
|
@ -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()
|
2
Download-page-as-pdf/requirements.txt
Normal file
2
Download-page-as-pdf/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
pyppdf==0.1.2
|
||||
pyppeteer==0.2.2
|
|
@ -165,6 +165,7 @@ So far, the following projects have been integrated to this repo:
|
|||
|[IMDBQuerier](IMDBQuerier)|[Burak Bekci](https://github.com/Bekci)
|
||||
|[URL shortener](url_shortener)|[Sam Ebison](https://github.com/ebsa491)
|
||||
|[2048](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/2048)|[Krunal](https://github.com/gitkp11)
|
||||
|[Download Page as PDF](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Download-page-as-pdf)|[Jeremias Gomes](https://github.com/j3r3mias)
|
||||
|
||||
|
||||
## How to use :
|
||||
|
|
Loading…
Reference in New Issue
Block a user