locked
How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net RRS feed

  • Question

  • User-1044947479 posted

    Hi Friends,

                  i have a webserver control in my application.i load the web browser control on a button click using the below code

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

                   AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False)

    End sub

    once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has a word with name Attorney then i want to get the url of that word.how to get this.Plz help me.

    with regards,

    Balaji.

    Friday, February 9, 2007 1:53 AM

All replies

  • User1176188571 posted
    what exactly you want give more details..?
    Friday, February 9, 2007 5:07 AM
  • User-1044947479 posted

    hi udkadam,

                    if the are words like this ATTORNEY,People in a web page with the hyper links then i want the url associated with these hyperlinks.

    with regards,

    Balaji. 

     

    Friday, February 9, 2007 7:16 AM
  • User-709143439 posted

    Try this, it will loop through links to show the links and text.  Code is for .NET not vb6

    Dim i As Integer = 0
      For Each Link As HtmlElement In AxWebBrowser1.Document.Links
                ListBox1.Items.Add(i & ". " & Link.InnerHtml & ": " & Link.OuterHtml)
                i += 1
               ' Add to find only Attorney info
                  'If Link.OuterHtml.Contains("Attorney") Then
                 '   Debug.Print(i - 1 & " " & Link.OuterHtml)
                 'End Add to find only Attorney info
                'End If
         Next


    Tuesday, December 8, 2009 11:41 AM
  • User-952121411 posted

    You could use JavaScript to loop through the <a> anchors collection on a page and then run logic when you find key words within the returned 'href' property.  The loop is below; it just does a JavaScript 'alert', but you could modify the JS to do whatever you need with the keywords:

    function LoopThroughAnchorCollection(){
    
        // get all links on page
        var anchors = document.getElementsByTagName("a");
        var size = anchors.length;
    
        // loop through anchors and display thier 'HREF' property
        for (var i = 0; i < size; i++) {
            
            alert(anchors[i].href);
    
           };
    
    }

    Here are a couple of links for reference:

    http://www.w3schools.com/JS/tryit.asp?filename=try_dom_anchor_href

    http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=215


     

    Monday, December 21, 2009 5:33 PM