How do I automatically download a PDF from a website?
I want to be able to download an arbitrary PDF from a website, but I don't know how to find a specific file name, and then how to automate the download.
What's the best way to do this? I tried some examples in the Python book: import mechanize. Br = mechanize.Browser() br.sethandlerobots(False) br.pdf') br.open("") response = br.response().read()
File = open('/home/me/Desktop/test.pdf', 'wb') file.write(response) file.close() print "Downloaded PDF." What I want is to be able to select any arbitrary file from a website, such as "" - for example. Here's an example of an API request for a random file that I did, which works: from urllib.request import urlretrieve url = "". File = open('1.pdf', 'wb') urllib.urlretrieve(url, file) print("Download finished.") I'm looking to see how I can build something that would allow me to pick an arbitrary file without having to figure out the exact file name and using a programmable API. If someone has an example, it would be awesome! If you want to download a file from a web page just like you do with urllib.urlretrieve(), the script would look like this: br = mechanize.Browser() response = br.open(url).
How do I download all files from a website?
Using the code shown below, I have been able to download individual files from a website.
However, for more than 100 files, this only ever downloads about 20, even though there are clearly many more.
Can anyone see what's going wrong? Thanks. Public Sub getfiles(). Dim uFile As Object, url As String, x As Integer, z As Integer. With CreateObject("MSXML2.XMLHTTP") .Open "GET", "", False .send If .readyState = 4 And .Status = 200 Then
Set uFile = .responseBody For z = 1 To uFile.DocumentElement.ChildNodes.Length
x = uFile.ChildNodes(z).OuterHtml
'Debug.Print x 'Debug.Print objHTMLDocument.getElementsByName("DIRNAME").Item(0).innerText
'MsgBox objHTMLDocument.getElementsByName("DIRNAME").Item(0).innerText
Debug.getElementsByName("DIRNAME").Item(0).innerText
Next z. .
Related Answers
What is the best way to extract data from a PDF?
I've been using ScraperWiki for a few years now and love it. If you'r...
How do I download a PDF from a locked website?
I'm a computer scientist studying at a technical unive...