Results 1 to 4 of 4

Thread: I must be close

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    15

    I must be close

    I have to be close on this. Basically it should track links posted on my webpage, go to the link, return to my webpage and check for next.

    Right now the first part:

    Code:
     Dim theElementCollection As HtmlElementCollection
            theElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
    
            Dim userName As String = textbox1.Text.Trim()
            Dim allLinks As HtmlElementCollection = WebBrowser1.Document.Links
    
            For Each link As HtmlElement In theElementCollection
    
                Dim linkfound As String = link.GetAttribute("href")
               
                If linkfound.Contains(userName) Then
                    WebBrowser1.Navigate(linkfound)
    
                    RichTextBox1.Text = RichTextBox1.Text & vbCrLf & linkfound & vbCrLf
                    Timer1.Start()
                    Exit For
                End If
    
            Next
    Works perfect. Saves a copy of link in richtextbox, browses to the page and returns. (return code elsewhere)

    My problem is the button starts a timer which should preform this task but now it should check links and compare them to existing ones in richtextbox. If the exact link is there do nothing and go to next foundlink. The timer code where the problem is:

    Code:
    Dim theElementCollection As HtmlElementCollection
                theElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
    
                Dim userName As String = textbox1.Text.Trim()
                Dim allLinks As HtmlElementCollection = WebBrowser1.Document.Links
    
                For Each link As HtmlElement In theElementCollection
    
                    Dim linkfound As String = link.GetAttribute("href")
                    If linkfound.Contains(userName) Then
                      
                        For Each linkUrl In RichTextBox1.Text
                            If linkUrl = linkfound Then
                                Exit For
                            Else
                                addressbar.Text = linkfound
                                WebBrowser1.Navigate(linkfound)
                                RichTextBox1.Text = RichTextBox1.Text & vbCrLf & linkfound & vbCrLf
                            End If
    
                        Next
    
                    Else
                        Exit For
    
                    End If
                Next
            End If

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: I must be close

    So what's the problem? Starting at a chunk of code and guessing at what is going to go wrong, where, and why, is difficult enough to do with code you have written yourself, doing that with somebody elses code is much more difficult.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    15

    Re: I must be close

    sorry should have been a bit clearer.

    The bottom code should be looking at the richtextbox which is storing the urls visited. I am trying to figure out the best way of taking a parsed url and compare it to the links in a richtextbox to see the url is already in the richtextbox. This way I wont keep going back to the same url

    The break seems to be the actual comparing of the parsed url and the richtextbox links. I am wondering if there is a better way to compare.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: I must be close

    Keep the visited url's in a list(Of string). Before you navigate to an url, check against the list. If the list doesn't contains the url then you add it to the list and navigate to that url. Otherwise, do nothing.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width