Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How to get text from webbrowser to vb.net <span> HELP!

Hi Forum

Thanks in advance who would help me fix this.
Tryed lot of things and i still have problem.

So let me explain

I want to store 3 Values from Webbrowser that are in <span> to vb.net label

Here is HTML ( of 3 Values i need )

HTML Code:
PHP Code

<?php 
<li class="_bnq48">
<
span class="_t98z6">
[
b]<!--[/b] react-text: 27 -->
[
b]<!--[/b] /react-text -->
<
span class="_fd86t">11</span>
[
b]<!--[/b] react-text: 29 --> posts<!-- /react-text -->
</
span>
</
li>




<
li class="_bnq48">
<
a class="_t98z6" href="/gembowa/reactions/">
[
b]<!--[/b] react-text: 32 -->
[
b]<!--[/b] /react-text -->
<
span class="_fd86t" title="772">772</span>
[
b]<!--[/b] react-text: 34 --> reactions<!-- /react-text -->
</
a>
</
li>



<
li class="_bnq48">
<
a class="_t98z6" href="/gembowa/Coins/">
[
b]<!--[/b] react-text: 37 -->
[
b]<!--[/b] /react-text -->
<
span class="_fd86t">264</span>
[
b]<!--[/b] react-text: 39 --> Coins<!-- /react-text -->
</
a>
</
li> 
I need these Values 11, 772, 264 storred to vb.net labels

I tryed following with 1 loop because all classes are same. ( NOT WORKING ):

Code:
Code
For Each h As HtmlElement In WebBrowser1.Document.GetElementsByTagName("span")
                If Not Object.ReferenceEquals(h.GetAttribute("className"), Nothing) AndAlso h.GetAttribute("className").Equals("_fd86t") Then
                    Label1.Text = h.InnerText
                    Exit For
                End If
            Next
Is there way to copy these values with .InnerHtml.Contains or .Contains and get thought "text": posts, reactions, coins ?

Thank you all,

Great forum.
I would personally recommend using htmlagilitypack, it is really easy to parse html using it. Then you can do something like this when you have htmlagilitypack all setup - the documentation is really easy btw.

For Each node As HtmlNode In htmldoc.DocumentNode.SelectNodes("//span[@class='_fd86t']")

then you can do

Dim value As String = node.InnerHtml

then you have the values

I can give you further guidence on how to set it up if you want?
Brandi Love, Thank you, imma try this.

One question, htmlagilitypack extract value without webbrowser navigation?

I'm kinda new to this.

I downloaded libary, what version should i use? Net45 ?

Okay i tryed it and nothing happens here is code:

Code
Imports HtmlAgilityPack
Imports System.Net
Imports System.IO
Imports System.Text
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim streamLink As String = "https://www.instagram.com/hackforums/"
        Try
            Dim request = CType(WebRequest.Create(streamLink), HttpWebRequest)
            Dim response As HttpWebResponse = CType(request.GetResponse, HttpWebResponse)
            Dim receiveStream As Stream = response.GetResponseStream
            Dim readStream As StreamReader = New StreamReader(receiveStream, Encoding.UTF8)
            Try
                Dim html As String = readStream.ReadToEnd
                Dim htmldoc As New HtmlDocument
                htmldoc.LoadHtml(html)
                For Each node As HtmlNode In htmldoc.DocumentNode.SelectNodes("//span[@class='_fd86t']")
                    Label1.Text = node.InnerHtml
                Next
            Catch ex As Exception
                Debug.WriteLine(ex.Message)
            End Try
        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try
    End Sub
End Class

Ex message: Object reference not set to an instance of an object.
Seems that value is null and can't extrack
You can use Regular Expressions for this easily.

Code
For Each m As Match In Regex.Matches(Webbrowser1.DocumentText, "<span class=""(.*?)"">([0-9]{1,10})</span>", RegexOptions.Multiline)
    MessageBox.Show(m.Groups(2).Value)
Next

and don't forget to import System.Text.RegularExpressions
(Sep 26, 2017 04:27 PM)Nikola Тesla Wrote:  You can use Regular Expressions for this easily.

Code
For Each m As Match In Regex.Matches(Webbrowser1.DocumentText, "<span class=""(.*?)"">([0-9]{1,10})</span>", RegexOptions.Multiline)
    MessageBox.Show(m.Groups(2).Value)
Next

and don't forget to import System.Text.RegularExpressions

Tryed not working.
(Sep 26, 2017 04:45 PM)botland Wrote:  Tryed not working.

Code
For Each m As Match In Regex.Matches(RichTextBox1.Text, "<span class=""(.*?)"">(.*?)</span>")
            MessageBox.Show(m.Groups(2).Value)
Next

Try this then?
(Sep 26, 2017 04:48 PM)Nikola Тesla Wrote:  
Code
For Each m As Match In Regex.Matches(RichTextBox1.Text, "<span class=""(.*?)"">(.*?)</span>")
            MessageBox.Show(m.Groups(2).Value)
Next

Try this then?

Na I can't find way.

Learning HtmlAgilityPack

I just extrack DOC data into textbox and search for that classname
and seems that it does not exist. BUT on browser inspect element it does.

Anyway i found this in DOC:

Quote:<meta content="1,045 Followers, 35 Following, 69 Posts" name="description" />


But one note: Followers, Following, Posts changes everytime so i need select node meta where is name ="description" and get attribute value of content.
Teach me how to get content values after it i will parse values. I just need single value.
If it's really bugging you that much, I can help you out through TeamViewer.
I feel like you're gonna have to work through this yourself mand. Just keep on testing. Like an easy way to check if htmlagility pack is working is just look at the html of the entire page and then you can then determine how you are going to scrape the selected parts.
Just note pretty much all the people in this thread are correct, but you choose which method you use as at the end of the day; it works right?

Dont let anyone tell you one is better than another unless there are real facts behind it.
[Image: F2G97kn.png]
(Sep 27, 2017 01:43 PM)Xogg Wrote:  Just note pretty much all the people in this thread are correct, but you choose which method you use as at the end of the day; it works right?

Dont let anyone tell you one is better than another unless there are real facts behind it.

Hi, I found best way.


(Sep 27, 2017 07:13 AM)Brandi Love Wrote:  I feel like you're gonna have to work through this yourself mand. Just keep on testing. Like an easy way to check if htmlagility pack is working is just look at the html of the entire page and then you can then determine how you are going to scrape the selected parts.

I got this working, thank you for letting me know about agiltypack this libary is powerfull just need learn select nodes and pretty much everything can be extracked from DOC.


(Sep 27, 2017 12:55 AM)DBots Wrote:  If it's really bugging you that much, I can help you out through TeamViewer.

Nah, i don't need help :)

Thank you everyone <3


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by D3ath_GuNJan 3, 2020 01:49 PM 4 251 Jan 3, 2020 01:49 PM
Last Post: Krysis
[.NET] by isuDec 25, 2018 03:53 PM 3 200 Dec 25, 2018 03:53 PM
Last Post: StarZ
[C#] by JASJun 13, 2017 04:07 PM 6 223 Jun 13, 2017 04:07 PM
Last Post: Ninja