You can try this quickly converted code to invoke a button which is C#
if (WebBrowser.Url.ToString == "http://www.Yoursite.com/" && WebBrowser.Document.Body.InnerText.Contains("Wiki") == true) {
if (WebBrowser.ReadyState == WebBrowserReadyState.Complete) {
WebBrowser.Document.GetElementById("username").SetAttribute("Value", textbox1.Text)
WebBrowser.Document.GetElementById("password").SetAttribute("Value", textbox2.Text);
}
WebBrowser.Document.GetElementById("Submit").InvokeMember("click");
}
You will need to look at Wikipedia Source code (Html) and see what Div tags have IDs and Class names. I.e.
<div id="SomeId" classname="SomeClass">Text you want</div>
Its those Classnames and IDs you need to loop through in the WebBrowser.Document.Body.innerhtml to get the text you need by iterating the class names of that tag.
You can use the
GetElementsByTagName("a")
to retrieve the html element collection of links. (The above would retrieve links since its looking for tags like
<a href="#">Text to get</a>
' a ' being the tag. ' href' being the class name attribute.
If you want to loop through Div tags, just change ' a ' to div, and change the class name accordingly relative to the tag you want to get.
You then need to cast that collection as you iterate through it to look for the Classname of the ' a ' tag using:
MainElement.GetAttribute("href") == "http://"
which will return the links if there is a match.
From there, you can use an If statement to check the
.inntertext
of the html element is not null and set the element to a declared variable where you can do as you please with the returned result.
I only have the code wrote out in .Net and don't have time to convert it, so you will need to convert it to C#, but I have also provided you with the links you need for achieving this above, and you can try convert some of the code with
Teleric
but my guess is you may need to manually change some of it yourself.
But I hope this quick post will give you a general insight how to approach this.
Dim MyString As String = Nothing
Dim myElement = (From MainElement As HtmlElement In WebBrowser.document.GetElementsByTagName("a").Cast(Of HtmlElement)()
Where MainElement.GetAttribute("href") = "http://"
Select MainElement)
If myElement(0) IsNot Nothing Then
myElement(0).InnerText = MyString
End If
Hope it helps.
Edit:
Link worth checking which might also be helpful to you with this solution.
Agility Pack Recommended by BillWoodruff