Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27346

VS 2012 For Each, If statements, and WebBrowser manipulation problem

$
0
0
Right, I already had a topic relating to this but it never went anywhere, so i am hoping some of you will help me with this as i explain step by step what i am trying to do. Now since i am having problems with this, i am asking if you guys can help me correct my code. Its not often i ask this, but been stuck on this issue for days, and normally i just ask for referrals and suggestions.... I'm going to write into the code to explain what i want it to do. so here it goes:

Code:

        For Each OfMyElements As HtmlElement In WebBrowser.Document.Links ' in this case its the links/urls
            Dim MyElementTarget As String = OfMyElements.OuterText ' i want the text of the url (not the actual url)
            Dim Include As Boolean = True ' havent worked out where i will use this yet but i am sure it be helpful :)
            Try 'incase the if statement goes bonkers i want to see whats wrong
                If MyElementTarget.Contains("@") = True Then ' i want to return only text from the urls which contain the @ symbol

                    TreeView.Nodes.Add(MyElementTarget) ' and if the @ symbol is true/found in url/outertext, then I want to add the outer text to a Treeview
                Else
                    TreeView.Nodes.Add("-- No other links --") if it is not found, then i want to tell the user that no other links are available
                End If
            Catch Bugs As Exception
                MessageBox.Show(Bugs.Message)
            End Try

        Next

Now there are a few problems with this. For a start, when i am using For Each and going through the list of urls, its going to output several times into the treeview that " no other links " . how can i stop it from doing that and just have it say it once instead?

There are also duplicate links which I don't want to get added to the TreeView, how can i stop that while its going through the For Each statement?

I also wanted to iterate through each link but at the same time, remove everything else on the page which was not either of these <h3><a href="#">Link</a></h3>

Appreciate if you guys can help me to build this code up the right way??? btw, if i cant do this properly, i will need to build a web service app which is going to add months onto this program....

if you have any questions, just ask me if something does not make sense to you.

Viewing all articles
Browse latest Browse all 27346

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>