|
-
Jun 13th, 2012, 08:09 PM
#1
Thread Starter
Junior Member
[RESOLVED] Read Part of an HTML Link and InvokeMember-Click
I would like to invoke a click on a link from a link that is generated by an HTML query. I am attempting to program an application that queries a website and am getting hung up where I download the .csv that is loaded by the website. Here is the link I am trying to read:
HTML Code:
<a href="http://www5.statcan.gc.ca/cansim/results/cansim9170974256855749928.csv">Download file from CANSIM (CSV Version, 5<abbr title="kilobyte">kb</abbr>)</a>
cansim9170974256855749928 from the url is not static and I don't know how to work around this. Is there a way to enable a clicking event on a random csv link? I have mashed together some failing attempts at this off and on for some time now and am now in your hands. All I have for code to show after all attempts is:
Code:
With WebBrowser1.Document
End With
Cross Posted Here
-
Jun 14th, 2012, 04:05 PM
#2
Addicted Member
Re: Read Part of an HTML Link and InvokeMember-Click
Loop through WebBrowser1.Document.Links (each link is a HTMLAnchorElement) looking for the link with innerText starting with "Download file from CANSIM (CSV Version". Call the Click method on that link.
Is your program written in VBScript or VBA?
-
Jun 14th, 2012, 08:13 PM
#3
Thread Starter
Junior Member
Re: Read Part of an HTML Link and InvokeMember-Click
Hi His Nibbs and thank you for the response. I will give that a go and hopefully all goes well. I am writing this with regular ol VB.NET. I posted in this forum because of the topic matter.
-
Jun 14th, 2012, 08:28 PM
#4
Thread Starter
Junior Member
Re: Read Part of an HTML Link and InvokeMember-Click
Ok so I have tried playing around with your suggestion but I'm not sure how to structure this. I have:
Code:
Imports System.Windows.Forms.LinkLabel
and then in the Class Form1 I have:
Code:
Dim lnk As Link
For Each lnk In WebBrowser1.Document.Links
If WebBrowser1.Document.GetElementById(lnk.ToString).InnerText = "Download file from CANSIM (CSV Version, 5kb)" Then
End If
Next
However this throws an error at run time saying "Unable to cast object of type 'System.Windows.Forms.HtmlElement' to type 'Link'."
I will keep tossing around some thoughts while I work on this but I am still stuck.
-
Jun 14th, 2012, 08:40 PM
#5
Thread Starter
Junior Member
Re: Read Part of an HTML Link and InvokeMember-Click
After some digging around on the interwebs I found the following but it doesn't find the innerText value of the link
Code:
For Each link As HtmlElement In WebBrowser1.Document.Links
If link.InnerText = "Download file from CANSIM (CSV Version, 5kb)" Then
WebBrowser1.Document.GetElementById(link.InnerText).InvokeMember("click")
End If
Next
-
Jun 14th, 2012, 09:08 PM
#6
Thread Starter
Junior Member
Re: Read Part of an HTML Link and InvokeMember-Click
Woot, this is finally behind me now. Thanks for the kick in the right direction His Nibbs, I have the following code which does the job nicely
Code:
For Each link As HtmlElement In WebBrowser1.Document.Links
If link.InnerText.Contains("Download file from CANSIM") Then
WebBrowser1.Navigate(link.GetAttribute("href"))
End If
Next
-
Jun 16th, 2012, 04:36 AM
#7
Addicted Member
Re: Read Part of an HTML Link and InvokeMember-Click
 Originally Posted by MorDred
I am writing this with regular ol VB.NET. I posted in this forum because of the topic matter.
You posted in the wrong forum then. The forums are arranged by programming language, not topic. But you got there in the end.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|