[RESOLVED] Web Scrapping (getting output from the web)
Hi,
I am trying to extract some data from the webpage's element. Since it is based on the input I type in, the length of the output is different for every different input.
The format of the data I am trying to extract is always as follows:
<div id="result"><div style="padding:0.6em;">Vast</div></div>
I want what ever word/phrase of any length that is between "0.6em;">" and "</div>"
earlier methods I've used for inputs was WebBrowser1.Document.GetElementById("Text").SetAttribute("value", TextBox1.Text)
I was wondering if there is something as simple for extracting the output.
Thanks in advance
Re: Web Scrapping (getting output from the web)
You can try:
vb Code:
Dim elem As HtmlElement = WebBrowser1.Document.GetElementByID("result")
Dim innerString As String = elem.InnerText
MsgBox(innerString)
Re: Web Scrapping (getting output from the web)
Actually, thanks so much. I just realised it was because the webpage didn't finish loading.
Re: Web Scrapping (getting output from the web)
What if there isn't an Id? Like in the example below:
Code:
<div class="dct-em">
<span class="dct-tt">A rope with its ends fastened at different points to a spar or other object in order to provide a purchase</span>
</div>
</li>
<li class="dct-em"
>
<div class="dct-em">
<span class="dct-tt">A team of people or animals, in particular</span>
</div>
</li>
<li class="dct-em"
>
<div class="dct-em">
<span class="dct-tt">A matched pair of horses, mules, or oxen</span>
</div>
I just want to extract the 3 chunks of text.
Re: Web Scrapping (getting output from the web)
Try something like this:
vb.net Code:
Dim InnerStringEnum As IEnumerable(Of String) = From h As HtmlElement In WebBrowser1.Document.GetElements.GetElementsByTagName("span") _
Where h.GetAttribute("className").Equals("dct-tt") _
Select h.InnerText
For each s As String in InnerStringEnum
MsgBox(s)
Next
Re: Web Scrapping (getting output from the web)
Thanks again, your solutions work great!