473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to Download a linked file on a webpage via Python

I am trying to use Python 2.7 to open a web browser and download and save a linked kml file.

The website is:
rmgsc.cr.usgs.gov/outgoing/GeoMAC/ActiveFirePerimeters.kml

When I run the code below, a new kml file appears to be saved on my drive, however it does not bring over the entire file. Instead of 154MB, it brings over a file that is only 17 bytes.

I can either go to the website (rmgsc.cr.usgs.gov/outgoing/GeoMAC/) and then click on a link named "ActiveFirePerimeters.kml", or go to the website with the kml file name included which automatically initiates a download. In IE9 I would then need to click a "Save" button, however in Chrome it appears to automatically download. However in both only 17bytes come across....

Here is my code for Internet Explorer:

Expand|Select|Wrap|Line Numbers
  1. import os, webbrowser
  2. target_dir = r"C:\DataTest"
  3. filename = "ActiveFirePerimeters.kml"
  4.  
  5. fullname = os.path.join(target_dir,filename)
  6. with open(fullname,"w") as f:
  7.    f.write("<html>....</html>")
  8.  
  9. url = "rmgsc.cr.usgs.gov/outgoing/GeoMAC/ActiveFirePerimeters.kml"
  10. webbrowser.open(url,True,True)
  11.  
  12. os.system("taskkill /F /IM iexplore.exe")
Aug 6 '13 #1
0 1242

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Létező | last post by:
Hi Python Fans! Could you send me a download URL of a compiled HTML Help (CHM) file for Python 2.2.3 ? Thanks: Complex
6
by: J. W. McCall | last post by:
Hopefully a simple question: how do I download a file (jpg image) to my hard drive from a website assuming I have its (the image's) URL? I tried urllib.urlretrieve() and it's not working. I'm...
2
by: SmilingPolitely | last post by:
I would like to have the properties of a linked file appear on the page linking to it, so that the user can see the date last modified and file size. I.E. <a href="filename>Click here to...
3
by: Chris | last post by:
Hi, in a webpage do I build a treeview displaying the content of a directory and its subdirectories. 1) Now, when I click on a filename that is listed in the treeview would I like to...
4
by: Nathan Sokalski | last post by:
I want to give visitors to my site the option of downloading a generated ..txt file by clicking a button. I know how to generate text files, but how do I cause the browser to pop up one of those...
4
by: majik92 | last post by:
I want a user to download to download bec.exe from download.php. But, the next time anyone accesses download.php, i want it to turn up a Error 404 page or simply a sentence saying "sorry, this file...
19
by: Dongsheng Ruan | last post by:
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data
4
Atran
by: Atran | last post by:
Hello EveryBody, How to Download A File using python? Thanks.
1
by: smitanaik | last post by:
how to write an api to download contents from webpage
1
by: Jalindar Gat | last post by:
Hi all, I am new bee in Python programming... I am trying to download web page using python code code: import urllib # Get a file-like object for the Python Web site's home page. f =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.