PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
HTML Problem-VBForums
Results 1 to 10 of 10

Thread: HTML Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2015
    Posts
    7

    Question HTML Problem

    how to get 'This Text Is Comment' Text in vb net?

    HTML Code:
    <div style="margin-bottom:10px;"> 
    			   
    			   <span id="4749988" style="">
    			   <a href="/of-somethinghow"><b>somethinghow</b></a>    
    
     <abbr class="blur" title="Fri, 12 Oct 2018 11:14:50 +0700">2 hrs </abbr>    <span class="blur"><span id="4749988">0</span> fun </span>
    
    <br> This Text Is Comment
    			   
    			        <div style="margin-top:5px;margin-bottom:5px"> 
    					
    					         
                         </div>
                         
                           </span>
                         
                            
                       
                         
                         
                         
    			   </div>
    Name:  1.PNG
Views: 275
Size:  1.1 KB

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,479

    Re: HTML Problem

    There is only one <br> tag so you could get the index of that tag, account for the length of the tag, and then get everything from that point to either the new line character or the next < character (then optionally trimming the whitespace). Something like the following:
    Code:
    Dim markup As String = <div style="margin-bottom:10px;">
                               <span id="4749988" style="">
                                   <a href="/of-somethinghow"><b>somethinghow</b></a>
                                   <abbr class="blur" title="Fri, 12 Oct 2018 11:14:50 +0700">2 hrs </abbr>
                                   <span class="blur">
                                       <span id="4749988">0</span> fun
                                     </span>
                                   <br/> This Text Is Comment
                                     <div style="margin-top:5px;margin-bottom:5px">
    
                                   </div>
                               </span>
                           </div>.ToString()
    
    'Get the index of "<br", then get the first ">" after the "<br"
    Dim start As Integer = markup.IndexOf("<br")
    Dim length As Integer = markup.IndexOf(">"c, start) - start
    
    'Set the start to where the "<br />" tag ends
    start += length + 1
    
    'Get the index of the first "<" after the "<br />" tag
    length = markup.IndexOf("<"c, start) - start
    
    'Get everything from our starting point to the first "<" character, but trim the leading/trailing whitespace
    Dim content As String = markup.Substring(start, length).Trim()
    
    'Display the text we just got
    Console.WriteLine(content)
    Console.ReadLine()

  3. #3
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,143

    Re: HTML Problem

    vb Code:
    1. Imports System.Text.RegularExpressions
    2.  
    3.  
    4. Public Class Form1
    5.     Private function GetBrTag (source As string) As string
    6.         return new Regex("(?i)(?<=<br>).+(?=<div style)",
    7.                          RegexOptions.Singleline).
    8.                          match(Me.RichTextBox1.text).Value
    9.     End function
    10. End Class

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2015
    Posts
    7

    Re: HTML Problem

    Quote Originally Posted by ident View Post
    vb Code:
    1. Imports System.Text.RegularExpressions
    2.  
    3.  
    4. Public Class Form1
    5.     Private function GetBrTag (source As string) As string
    6.         return new Regex("(?i)(?<=<br>).+(?=<div style)",
    7.                          RegexOptions.Singleline).
    8.                          match(Me.RichTextBox1.text).Value
    9.     End function
    10. End Class
    very sorry,
    what i mean is how to get the text from webbrowser.

    i use this code but it shows nothing

    Code:
     Dim el As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("br")
                For Each value As HtmlElement In el
                    If value.GetAttribute("") Then
                        MsgBox(value.InnerText)
                    End If
                Next

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2015
    Posts
    7

    Re: HTML Problem

    HTML Code:
    <div style="margin-bottom:10px;"> 
    			   
    			   <span id="4749988" style="">
    			   <a href="/of-somethinghow"><b>somethinghow</b></a>    
    
     <abbr class="blur" title="Fri, 12 Oct 2018 11:14:50 +0700">2 hrs </abbr>    <span class="blur"><span id="4749988">0</span> fun </span>
    
    <br> This Text Is Comment
    			   
    			        <div style="margin-top:5px;margin-bottom:5px"> 
    					
    					         
                         </div>
                         
                           </span>
                         
                            
                       
                         
                         
                         
    			   </div>
    Name:  1.PNG
Views: 275
Size:  1.1 KB

    or is there a way to get that html code in vb net?
    cause i copied that directly from chrome's ie

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,479

    Re: HTML Problem

    What is the website that you're trying to scrape the HTML from?

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2015
    Posts
    7

    Re: HTML Problem

    Quote Originally Posted by dday9 View Post
    What is the website that you're trying to scrape the HTML from?
    https://1cak.com/2444881

    I want to get the comments to my project

  8. #8
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,143

    Re: HTML Problem

    Quote Originally Posted by Abd Muthalib Isman View Post
    very sorry,
    what i mean is how to get the text from webbrowser.

    i use this code but it shows nothing

    Code:
     Dim el As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("br")
                For Each value As HtmlElement In el
                    If value.GetAttribute("") Then
                        MsgBox(value.InnerText)
                    End If
                Next
    What do you expect?

    Code:
    value.GetAttribute("")


    GetAttribute is blank.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2015
    Posts
    7

    Re: HTML Problem

    Quote Originally Posted by ident View Post
    What do you expect?

    Code:
    value.GetAttribute("")


    GetAttribute is blank.
    Then what should i fill it with?
    There's no attribute in <br> element afterall
    I tried without if and still shows nothing

  10. #10
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,143

    Re: HTML Problem

    Quote Originally Posted by Abd Muthalib Isman View Post
    Then what should i fill it with?
    There's no attribute in <br> element afterall
    I tried without if and still shows nothing
    *shrug* I don't know. You have the same eyes to see the same source as me. Web browsers are UI elements. They are not for you getting the source of a page. I and Dday have shown you how to extract the data already so what is the issue?

    If you are using the web browser control than we should assume you have read its documentation. Then I assume you know it has a HtmlElement.InnerText Property correct?

    How you get the source does not change both the examples you have been provided.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width