forked from dilrajsingh1997/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb2pdf.py
More file actions
29 lines (19 loc) · 649 Bytes
/
web2pdf.py
File metadata and controls
29 lines (19 loc) · 649 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import requests
from bs4 import BeautifulSoup
BASE_URL = "http://www.web2pdfconvert.com/engine?cURL="
def web2pdf(PAGE_URL,file_name):
URL = BASE_URL + PAGE_URL
response = requests.get(URL)
soup = BeautifulSoup(response.content)
PDF_URL = soup.find('a')['href']
PDF_RESP = requests.get(PDF_URL)
with open(file_name+'.pdf','wb') as f:
f.write(PDF_RESP.content)
return
def main():
PAGE_URL = raw_input("Enter the URL of the webpage you want to convert to a pdf:")
file_name = raw_input("Enter the file name:")
web2pdf(PAGE_URL,file_name)
print "Done"
if __name__ == "__main__":
main()