|
-
Feb 18th, 2010, 11:03 AM
#1
Thread Starter
New Member
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
-
Feb 18th, 2010, 11:32 AM
#2
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
 
-
Feb 18th, 2010, 12:38 PM
#3
Thread Starter
New Member
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.
-
Feb 18th, 2010, 04:32 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|