Results 1 to 6 of 6

Thread: Help with HtmlAgilityPack only grab last line

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2017
    Posts
    5

    Help with HtmlAgilityPack only grab last line

    Html
    Code:
    <div class="category-3223">
    <span id="line_1">LINE 1 </span>
    <span id="line_2">LINE 2</span>
    </div>
    My working code (but only grab line2)
    Code:
     Dim col As HtmlNodeCollection =
              doc.DocumentNode.SelectNodes(".//span[contains(@id, 'line_')]")
    How to grab all line?? (LINE 1 and LINE 2) because my code only grab LINE 2

    Thanks.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Help with HtmlAgilityPack only grab last line

    How do you know it's onlhy grabbing the one line? SelectNodes returns multiple notes... so what are you using to verify multiple nodes?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2017
    Posts
    5

    Re: Help with HtmlAgilityPack only grab last line

    because I have tried that code and I dont know why


    Code:
    Dim col As HtmlNodeCollection =
              doc.DocumentNode.SelectNodes(".//div[contains(@class, 'category-')]")
    When I use code above it works by grabbing LINE 1LINE 2 without enter.
    The point is how I can grab
    LINE 1
    LINE 2

    Thanks.

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Help with HtmlAgilityPack only grab last line

    Try modifying the SelectNodes expression to

    Code:
    .//div//span[contains(@id, 'line_')]
    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2017
    Posts
    5

    Re: Help with HtmlAgilityPack only grab last line

    Quote Originally Posted by KGComputers View Post
    Try modifying the SelectNodes expression to

    Code:
    .//div//span[contains(@id, 'line_')]
    - kgc
    Thanks for reply and alternative solution, but it's still only grab last line (LINE 2)

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Help with HtmlAgilityPack only grab last line

    Quote Originally Posted by Oshix View Post
    because I have tried that code and I dont know why


    Code:
    Dim col As HtmlNodeCollection =
              doc.DocumentNode.SelectNodes(".//div[contains(@class, 'category-')]")
    When I use code above it works by grabbing LINE 1LINE 2 without enter.
    The point is how I can grab
    LINE 1
    LINE 2

    Thanks.
    Quote Originally Posted by Oshix View Post
    Thanks for reply and alternative solution, but it's still only grab last line (LINE 2)
    I'm going to try one more time... HOW are you figuring out that it is only grabbing one line? What is is you are doing that makes you go "It only has the one line, where's the other one?" ... you haven't shown us any new code or steps you're taking to validate the problem. Are you checking the count, the length, or what? What is it you then do with col to determine it has only one line in it?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width