Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:57:58+00:00 2026-05-25T12:57:58+00:00

Code <div id=content> <div class=sample>sample text</div> <div class=datebar> <span style=float:right>some text1</span> <b>some text2</b> </div>

  • 0

Code

    <div id="content">
        <div class="sample">sample text</div>
        <div class="datebar">
           <span style="float:right">some text1</span>
           <b>some text2</b>
        </div>
     <p>paragraph 1</p>
     <p>paragraph 2</p> 
   </div>

I want to get data that in <p> tags or you can say that is coming after <div class="datebar">.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:57:58+00:00Added an answer on May 25, 2026 at 12:57 pm
    //div[@id="content"]/p/text()
    

    Would achieve what you’re asking for with your provided sample.


    Update
    If you only wanted those <p> that came after <div class="datebar">. The following should work:

    //div[@id = 'content']/p[preceding-sibling::div[@class='datebar']]/text()
    

    Another Update – For Kirill

    Here’s a sample of HTML which has an extra <p> before <div class="datebar"> and xpath expressions tested using python.

    Obviously, the solution depends on what the full input HTML is and what the OP wants to extract, neither of which are clear at the moment.

    >>> from lxml import etree
    >>> doc = etree.HTML("""
    ... <div id="content">
    ...   <div class="sample">sample text</div>
    ...   <p>paragraph 1</p>
    ...   <div class="datebar">
    ...     <span style="float:right">some text1</span>
    ...     <b>some text2</b>
    ...   </div>
    ...   <p>paragraph 2</p>
    ...   <p>paragraph 3</p>
    ... </div>""")
    >>> # My first suggestion
    ... doc.xpath("//div[@id='content']/p/text()")
    ['paragraph 1', 'paragraph 2', 'paragraph 3']
    >>> # Kirill's solution
    ... doc.xpath("//div[@id = 'content' and div[@class = 'datebar']]/p/text()")
    ['paragraph 1', 'paragraph 2', 'paragraph 3']
    >>> # My response to Kirill
    ... doc.xpath("//div[@id = 'content']/p[preceding-sibling::div[@class='datebar']]/text()")
    ['paragraph 2', 'paragraph 3']
    

    Kirill’s expression of //div[@id = 'content' and div[@class = 'datebar']]/p/text() does not select

    only those p which parent div has @id = 'content' and have preceding div with @class = 'datebar'

    As stated in his comments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The HTML: <div class=first id=first_id> <div class=second>text sample</div> <div class=third><button type=submit class=some_class id=some_id>send</button></div> </div>
The code for the asp.net page is: <div class=facebox_content> <% if (CurrentUser.Role == Free)
Consider the following html code: <div id='x'><div id='y'>Y content</div>X content</div> I'd like to extract
I have this code snippet: <div id=div1> </div> <div id=div2> <h3>This is the content</h3>
what is the proper code for this? in div style code. I know how
Imagine I have the following code (simplified regarding my real context of course): <div
I have this code: $(div[id^='intCell']).mouseover(function() { $(this).css({ border:,1px solid #ff097c}); }).mouseout(function() { $(this).css({border:,1px solid
I am using the following code to store values in aspx session. Code: $(div.menu_body
i have following code to show div on page <div id=all_users> <div id=user11 userid=11
I'm using the simple jQuery DIV refresh code. var refreshId = setInterval(function() { $('#refreshdash').load('dashboard.php?cache=');

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.