Cory Posted November 23, 2009 Report Share Posted November 23, 2009 As you may know I don’t like using IE or any web browser for automated web tasks. Instead I would use some downloader program to get the job done. But that wasn’t very elegant as it required me to distribute another app and make firewall adjustments to all machines running it. So I went hunting again and found this very handy VBScript. You give it a URL and a local path and file name and it downloads it for you! It’s fast and if you choose to capture the console output the macro will not advance until it’s done. I’ve been using it to download torrents on RSS feeds and it has been working very reliably. But the best part is that the script is saved in the file. In this example I use the variables %URL to Download% and %Local File Name%, you can see them in the script. ' Set your settings strFileURL = "%URL to Download%" strHDLocation = "%Local File Name%" ' Fetch the file Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") objXMLHTTP.open "GET", strFileURL, false objXMLHTTP.send() If objXMLHTTP.Status = 200 Then Set objADOStream = CreateObject("ADODB.Stream") objADOStream.Open objADOStream.Type = 1 'adTypeBinary objADOStream.Write objXMLHTTP.ResponseBody objADOStream.Position = 0 'Set the stream position to the start Set objFSO = Createobject("Scripting.FileSystemObject") If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation Set objFSO = Nothing objADOStream.SaveToFile strHDLocation objADOStream.Close Set objADOStream = Nothing End if Set objXMLHTTP = Nothing As a practical example I‘ll describe the macro I wrote this weekend. I am a Vikings fan but do not get DirecTV but want to watch all my games. There are private torrent sites where people post torrents of games but they are a little strange. You see most torrent sites have RSS (XML structured web pages) feeds which list all the latest posts. Most torrent sites will have the torrent URL in the link section but these guys link to another page that you have to go to where you can download the torrent. Personally I think they are just trying to discourage any automation but what this means is we can’t use the traditional RSS downloaders for our torrent clients. The other problem here is that because it’s a private tracker there are a limited number of lechers (downloaders) and since we are scrutinized on our ratio if you are tail end Charlie all the time your ratio will suck and you risk getting the boot. So I essentially created a macro to be an RSS downloader. What I do is have this script download the RSS feed to a file. I then parse that XML into a series of arrays with descriptions, links, sizes and so on. I even parse out the size from the description so I don’t accidently step on an MPEG2 version. I then check every description looking for Vikings games. It does this every 5 minutes. If I do find a game it follows the link to the next page where it downloads that file. In that file it finds the unique string of text which is the beginning to the torrent URL. I then cut out the URL from the rest of the HTML and use this VBScript again to download the torrent file to the drop folder (a folder monitored by the torrent software where files are automatically inducted). It then records the title of the torrent to be saved in a file that will prevent it from being downloaded again in the future. But the important thing is that this is all being done in macro memory and does not ever involve a web browser. Not only that but it’s faster because I’m not downloading all the graphics, advertising and especially not running any scripts in the web page like a browser will. No timing issues, not waiting for a web page to load... It all just works flawlessly and invisibly every time. Anyway given the problems users have with web page timing I thought I would share this as a solution. Manipulating the variables is a little more advanced but it’s easy to learn. Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.