title: How to download a web page as a PDF using Python?
body: <p>I want to make a script that can download a website as a PDF. the user should be able to enter a URL (<a href="https://stackoverflow.com/">https://stackoverflow.com/</a>) and a file path for the PDF to download to (c:\Bob\PDF).</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>import requests
  import pdfkit
  
  url = input("Please enter the url of the file you want to download.")
  pdf = pdfkit.from_url(url, "file.pdf")
  path = input("Please enter the file path that you would like the file to 
  download to. c:\Bob\PDF is an example of a valid file path.")
  
  print("Download starting.")
  r = requests.get(pdf)
  
  with open(path, 'wb') as f:
      f.write(r.content)
  </code></pre>
  
  <p>For some reason, the PDF doesn't download. I think I need to first convert the web page to HTML, and then convert it to a PDF so it can download, but I'm not sure how to go about doing this. Any help is greatly appreciated.</p>