I need to download a bunch of pdf files from the web. I usually use the urllib3 library, but it is a corporate website with authentication. I can download a normal html web using the following:
url = 'https://corpweb.example/index.html'
h = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
h.SetAutoLogonPolicy(0)
h.Open('GET', url, False)
h.Send()
result = h.responseText
But this solution doesn't works with a PDF.
url = "https://corpweb.example/file.pdf"
h = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
h.SetAutoLogonPolicy(0)
h.Open('GET', url, False)
h.Send()
with open(filename, 'wb') as f:
f.write(h.responseText)
I get an error:
TypeError: a bytes-like object is required, not 'str'
What can I do?