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 7442709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:13:00+00:00 2026-05-29T11:13:00+00:00

i am using the following code as input to dom document <li id=SalesRank> <b>Amazon

  • 0

i am using the following code as input to dom document

<li id="SalesRank">
<b>Amazon Best Sellers Rank:</b>
#20,267 Paid in Kindle Store (
<a href="http://www.amazon.com/gp/bestsellers/digital-text/ref=pd_dp_ts_kstore_1/190-9295683-0277616">See Top 100 Paid in Kindle Store</a>
) 
<ul class="zg_hrsr">
<li class="zg_hrsr_item">
<span class="zg_hrsr_rank">#15</span>
<span class="zg_hrsr_ladder">
in 
<a href="http://www.amazon.com/gp/bestsellers/digital-text/ref=pd_zg_hrsr_kstore_1_1">Kindle Store</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/154606011">Kindle eBooks</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/157325011">Nonfiction</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/292975011">Lifestyle & Home</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/156699011">Home & Garden</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/156828011">Gardening & Horticulture</a>
 > 
<b>
<a href="http://rads.stackoverflow.com/amzn/click/156847011">Greenhouses</a>
</b>
</span>
</li>
<li class="zg_hrsr_item">
<span class="zg_hrsr_rank">#26</span>
<span class="zg_hrsr_ladder">
in 
<a href="http://www.amazon.com/gp/bestsellers/digital-text/ref=pd_zg_hrsr_kstore_2_1">Kindle Store</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/154606011">Kindle eBooks</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/157325011">Nonfiction</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/292975011">Lifestyle & Home</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/156699011">Home & Garden</a>
 > 
<a href="http://rads.stackoverflow.com/amzn/click/156828011">Gardening & Horticulture</a>
 > 
<b>
<a href="http://rads.stackoverflow.com/amzn/click/156849011">House Plants</a>
</b>
</span>
</li>
</ul></li>

i am using the following xpath query to extract data with textContent..

$xpath_cat->query('//li[@id="SalesRank"]');

you can check the output, it includes the data which is including in all the li tags with id=salrsrank... while i want to get only the #20,267 paid in kindle store..

so the output required is

#20,267 Paid in Kindle Store

how can i modify my xpath to get the required output?

Update in code

i tried the solution provided below and used the xpath

$xpath_cat->query('//li[@id="SalesRank"]/text()');

but now, the output is

( [0] => [1] => #20,267 Paid in Kindle Store ( [2] => )

how can i fix this?

  • 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-29T11:13:02+00:00Added an answer on May 29, 2026 at 11:13 am

    Does //li[@id='SalesRank']/text() work for you?

    Update 1

    If the text you want will always be in that location, then

    substring-before(normalize-space(//li[@id='SalesRank']/text()[2]), ' (')
    

    will return

    #20,267 Paid in Kindle Store
    

    This uses normailize-space to strip out extraneous whitepspace, and substring-before to select all text before the first occurence of ” (“.

    This problem will be much easier if you can get the target text in its own node, like:

    <b>Amazon Best Sellers Rank:</b>
    <span>#20,267 Paid in Kindle Store</span> (
    <a href="http://www.amazon.com/gp/bestsellers/digital-text/ref=pd_dp_ts_kstore_1/190-9295683-0277616">See Top 100 Paid in Kindle Store</a>
    ) 
    

    <span/> has no effect on rendering and allows you to specifically select the text you want.

    If either the second solution doesn’t work in all cases, and you cannot get the target text in its own now, you will have to rely on some post-processing in the host language (PHP I presume).

    Hope this helps,

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

Sidebar

Related Questions

Using the following code var newDiv = $(document.createElement(div)); var newTextBox; newTextBox = $(document.createElement(input)) .attr(type,
I am using regular expressions to validate user input. The following code collects a
I'm using following code to assign id of input tag when they are cloned.Is
i am using following code to set an image as submit button *<input type=submit
Given the following PHP code using DOMDocument : $inputs = $xpath->query('//input | //select |
I am using following CSS code to align Input Boxes, but still nothing seems
I am using the following code but haven't tried it yet: <input type=checkbox id=<bean:write
I am using the following code to capture change text in HTML inputs: $(document).ready(function()
I am using the following C code to take input from user until EOF
I am using the following code to disable the submit button $(input[type='submit']).attr(disabled, disabled); And

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.