i want download file webpage. webpage has 1 .zip file (that's want download), when click on .zip file, starts download url doesn't change (the url still remains of form http://ldn2800:8080/id=2800). how can download using python, considering there no url of form http://example.com/1.zip
?
also, when directly go page http://ldn2800:8080/id=2800, opens page .zip file doesn't download without clicking. how download using python?
update: right i'm doing way:
if (str(dict.get('id')) == winid): #or str(dict.get('id')) == linuxid): #if str(dict.get('number')) == buildno: buildtypeid = dict.get('id') id = dict.get('id') downloadurl = "http://example:8080/viewtype.html?buildid=26009&tab=artifacts&buildtypeid=" + id directory = bindingsdest + "\\" + buildno if not os.path.exists(directory): os.makedirs(directory) filename = none if buildtypeid == linuxid: filename = linuxlib + "-" + buildno + ".zip" elif buildtypeid == winid: filename = winlib + "-" + buildno + ".zip" if filename not none: print(dict) downloadfile(downloadurl, directory, filename) def downloadfile(downloadurl, directory, filename, user=user, password=password): if user not none , password not none: request = requests.get(downloadurl, stream=true, auth=(user, password)) else: request = requests.get(downloadurl, stream=true) open(directory + "\\" + filename, 'wb') handle: block in request.iter_content(1024): if not block: break handle.write(block)
but, creates zip in required location zip can't opened , has nothing. can done: searching filename on webpage , download pattern matched?
check http status code make sure no error happened. may use builtin method raise_for_status so: https://requests.readthedocs.io/en/master/api/#requests.response.raise_for_status
def downloadfile(downloadurl, directory, filename, user=user, password=password): if user not none , password not none: request = requests.get(downloadurl, stream=true, auth=(user, password)) else: request = requests.get(downloadurl, stream=true) request.raise_for_status() open(directory + "\\" + filename, 'wb') handle: block in request.iter_content(1024): if not block: break handle.write(block)
are sure there no networking issue such proxy/fw/etc ?
edit: according above comment, i'm not sure answers actual problem. revised answer:
you access web page containing link zip file. link, say, same page itself. if click on in browser, downloads file instead of reaching html page again. that's strange can explained in various ways. please copy/paste whole html page code (including link zip file), understanding issue.
Comments
Post a Comment