From https://research.un.org/en/docs/ga/quick/regular/76 I intend to download the first resolution (A/RES/76/307), which has the link (https://undocs.org/en/A/RES/76/307) and which then is transformed to https://documents-dds-ny.un.org/doc/UNDOC/GEN/N22/587/47/PDF/N2258747.pdf?OpenElement , when clicked on.
I use the standard code to download pdfs:
import requests
url = "https://undocs.org/en/A/RES/76/307"
response = requests.get(url)
print(response.status_code)
print(response.content)
with open("document.pdf", "wb") as f:
f.write(response.content)
While the status_code indicates everything is okay (200), the content simply is:
b'\n<head>\n</head>\n<body text="#000000">\n<META HTTP-EQUIV="refresh" CONTENT="1; URL=/tmp/1286884.54627991.html">\n</body>\n</html>\n'
, which is evidently not the actual content of the document. A pdf file is saved, but it is much too small and I cannot open it with Document viewer ("File type HTML document (text/html) is not supported").
How can I download that pdf file using python?