I am trying to write some script that will download a pdf from a URL to my pc. Looking around the internet, I have found a few examples of what I am trying to accomplish. I'm very very new to Python and keep getting a syntax error in my code.
import requests
url = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'
response = requests.get(url)
with open('C:\Users\User\PycharmProjects\PDFTest\FolderTest\dummy.pdf', 'wb') as f:
f.write(response.content)
The error I receive is:
File "C:\Users\User\PycharmProjects\PDFTest\main.py", line 7
with open('C:\Users\User\PycharmProjects\PDFTest\FolderTest\dummy.pdf', 'wb') as f:
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Process finished with exit code 1
I'm running everything within a VM if that is of any consequence and on Python 3.9.1. I see that the syntax error is at the comma, but everything I see says the comma is a must. Any help would be greatly appreciated. My programming experience is limited to a few semesters of C++ in college and loads of Python tutorials and videos.
My end goal for this project (once I get this part working) is to cycle through a domain to download PDF's. They are all stored as Https://www.examplesite.com/1000.pdf; ...com/1001.pdf; ...com/1002.pdf; etc. I think I can accomplish this by running the above in a for loop and increasing the pdf URL (a number) with ++. Thanks for the help!