VBScript Help (logging in and downloading from link)

Author Message
lavabird1998

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 1/20/2012
  • Status: offline
VBScript Help (logging in and downloading from link) Friday, January 20, 2012 7:57 AM (permalink)
0
Hello Everyone,
I’m having trouble with a .VBS. I have no previous experience when it comes to VBScript. The following script should start Internet Explorer, Login to my account, and download the latest .wav file to C:\Documents and Settings\aharvey\Desktop\data\New.wav. The problem is identified in the following code.
 
 Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True   IE.Navigate "http://www.website.com"   While IE.Busy Wend   IE.Document.All.Item("user").Value = "Password" IE.Document.All.Item("pass").Value = "Username"   IE.Document.All.Item("loginButton").Click   While IE.Busy Wend   strFileURL =  IE.document.links(1) ‘*problem* strHDLocation = "C:\Documents and Settings\aharvey\Desktop\data\New.wav" 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 objADOStream.Write objXMLHTTP.ResponseBody objADOStream.Position = 0 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 

 
I combined two working scripts to create this script. The first logs in and navigates to the main page. The second downloads a file using a URL and a destination. I believe the problem is where I put the two together. At strFileURL =  IE.document.links(1) I should be setting strFileURL to a URL. I need help identifying the destination of IE.document.links(1). The link changes each time I log in and I would not be able to identify it. Tweaks to the code in places where it doesn’t make sense would also be highly appreciated.
 
Thank you in advance,
Andrew J. H.
 
 
#1
    lavabird1998

    • Total Posts : 3
    • Scores: 0
    • Reward points : 0
    • Joined: 1/20/2012
    • Status: offline
    Re:VBScript Help (logging in and downloading from link) Friday, January 20, 2012 8:15 AM (permalink)
    0
    I am sorry if the code above is not visible. Please refer to the following.
     
    (Code begins)
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
     
    IE.Navigate "http://www.website.com"
     
    While IE.Busy
    Wend
     
    IE.Document.All.Item("user").Value = "Password"
    IE.Document.All.Item("pass").Value = "Username"
     
    IE.Document.All.Item("loginButton").Click
     
    While IE.Busy
    Wend
     
    strFileURL =  IE.document.links(1) ‘*problem*
    strHDLocation = "C:\Documents and Settings\aharvey\Desktop\data\New.wav"
    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
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0
    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
    (Code ends)
     
    I was unable to edit the main post.
     
    #2
      59cobalt

      • Total Posts : 981
      • Scores: 91
      • Reward points : 0
      • Joined: 7/17/2011
      • Status: offline
      Re:VBScript Help (logging in and downloading from link) Friday, January 20, 2012 11:08 AM (permalink)
      5
      Does the link you're looking for have any specific characteristics? If so, you could iterate over the .links collection with a for loop and select the matching link.
       
      #3
        lavabird1998

        • Total Posts : 3
        • Scores: 0
        • Reward points : 0
        • Joined: 1/20/2012
        • Status: offline
        Re:VBScript Help (logging in and downloading from link) Friday, January 20, 2012 4:17 PM (permalink)
        0
        Thank you 59cobalt for your help!
        As i said before, I have no VBScript experience and do not know how to access the .links collection. The link I am trying to access always appears second on the page. This is the link that was there on the latest log in /tts/speech/71d1c28c9e23264d5f219ae765cc9492.wav. The numbers change but the /tts/speech/ always remains the same. The only other link on the page is http://www.your-files.website.com/~ttsweb/tts/faq.php#WebPolicy. I have determined the links using the source code so I know they are correct.
         
        #4
          59cobalt

          • Total Posts : 981
          • Scores: 91
          • Reward points : 0
          • Joined: 7/17/2011
          • Status: offline
          Re:VBScript Help (logging in and downloading from link) Saturday, January 21, 2012 11:55 AM (permalink)
          0
          Try something like this:
          For Each link In IE.document.links
           If Left(link, 12) = "/tts/speech/" Then strFileURL = link
          Next

           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9