Solved

How to download an XML file from a url and save it into local drive

Posted on 2009-05-08
13
361 Views
Last Modified: 2012-05-06
I need a simple script that downloads and xml from a web line and save it into the local drive.


Thank you in advance.



0
Comment
Question by:ABalfaqih
  • 5
  • 4
  • 3
13 Comments
 
LVL 3

Expert Comment

by:SalmanZG
ID: 24342331
Hope this helps:

MsgBox getWebPage("http://www.google.com")


Function getWebPage(url)
      Set xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
      xmlhttp.open "get", url, False
      xmlhttp.send
      getWebPage = xmlhttp.responseText
End Function
0
 
LVL 3

Expert Comment

by:SalmanZG
ID: 24342363
Just to make solution complete ... saveFile sub included.

x = getWebPage("http://www.google.com")
saveFile "C:\temp\test2.html", x

Function getWebPage(url)
      Set xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
      xmlhttp.open "get", url, False
      xmlhttp.send
      getWebPage = xmlhttp.responseText
      Set xmlhttp = Nothing
End Function

Sub saveFile(fileName, content)
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set t = fso.OpenTextFile(fileName, 8, True)
    t.WriteLine (content)
    t.Close
    Set t = Nothing
    Set fso = Nothing
End Sub
0
 

Author Comment

by:ABalfaqih
ID: 24342460
Thank you for the quick reply.
I was thinking of downloading an xml file like this (http://thestar.com.my/rss/worldupdates.xml) into my local drive, and saved as an .xml file.

0
 
LVL 3

Expert Comment

by:SalmanZG
ID: 24342521
This will work fine - simply put your url as the parameter of the getWebPage function.

x = getWebPage("http://thestar.com.my/rss/worldupdates.xml")
0
 
LVL 2

Accepted Solution

by:
Nas-Banov earned 125 total points
ID: 24342717
Just open the URL (http://thestar.com.my/rss/worldupdates.xml) in a browser (IE or Firefox), right-click "View Source" and from there File / Save As... and select where to save the XML file.
0
 

Author Closing Comment

by:ABalfaqih
ID: 31579709
Great, it is a lot simple than I thought. Thanks.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:ABalfaqih
ID: 24344038
Nas,

I needed the script as I pass the values of the url and path in the local drive using another software. It is not done manual.  
I already have another script that I wrote, but wanted to see a different way of doing it.


0
 
LVL 3

Expert Comment

by:SalmanZG
ID: 24344589
Hi ABalfaqih,
Does my solution satisfies your need? I was wondering about acceptance of solution without the script.
0
 
LVL 2

Expert Comment

by:Nas-Banov
ID: 24345398
It's unclear what kind of coding you are doing (server-side, client-side, batch etc). This can be written differently in different languages. For example, if you have Python installed, try the one below


import urllib
 

f = open ('somename.xml', 'w')

f.write(urllib.urlopen("http://yahoo.com").read())

f.close()

Open in new window

0
 

Author Comment

by:ABalfaqih
ID: 24346329
Salman code was what I wanted to see. And it workded. Nas suggestion was correct but I wanted the script as I was doing some sort of client based application. I have another script that manipulates further the XML.

As of the Python code, I am impressed with so few lines you could do the same. Just to confirm, does it include the saving of the file too?
0
 
LVL 2

Expert Comment

by:Nas-Banov
ID: 24346539
yes, the python snippet includes the url reading and file writing
0
 

Author Comment

by:ABalfaqih
ID: 24346647
Nas,

I am impressed.You got me interested in Python... it must be one hell of a language. Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to setup 18 79
array220 challenge 8 46
stringclean challenge 26 56
wordcount challenge 11 75
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now