I written a code to download a pdf file from a link using request
import requests
url = "https://disclosure.bursamalaysia.com/FileAccess/apbursaweb/download?id=231746&name=EA_DS_ATTACHMENTS"
response = requests.get(url)
with open("EA_DS_ATTACHMENTS.pdf", "wb") as f:
f.write(response.content)
print("PDF downloaded successfully!")
Of course, it doesn't work. It instead downloads a PDF that is unreadable. I suspect its because it isn't a proper PDF download link, but then again I'm not really sure since im new to this.
It is returning a 403 response when using requests. It looks like it is blocking based on the user agent in the headers. You can use custom headers to mimic your browser's user agent to get the PDF document.