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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:45:36+00:00 2026-06-07T04:45:36+00:00

I have this Xpath query inside a loop, //div[@class=’listing_content’][#{i}]/div/div/h3/a/text() I want to process each

  • 0

I have this Xpath query inside a loop,

//div[@class='listing_content'][#{i}]/div/div/h3/a/text()

I want to process each node individually

The problem it gives the correct nodes, but all of them at once at once.

Also when i > 1, it returns nothing at all?

for i in (1...30)
  name = page.xpath("//div[@class='listing_content'][#{i}]/div/div/h3/a/text()")
  puts "this is name"
  puts name

  #Get Business phone
  phone = page.xpath("//div[@class='listing_content'][#{i}]//span[@class='business-phone phone']/text()")
  puts "this is phone"
  puts phone

  #Get Business website(if any)
  puts "this is website"
  website = page.xpath("//div[@class='listing_content'][#{i}]//li[@class='website-feature']//@href")
  puts website
end
  • 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-06-07T04:45:38+00:00Added an answer on June 7, 2026 at 4:45 am

    Also when i > 1, it returns nothing at all?

    This is the second most FAQ in XPath:

    Use:

    (//div[@class='listing_content'])[#{i}]/div/div/h3/a/text()
    

    The cause of the observed behavior is that in XPath the [] has higher precedence (priority) than the // pseudo-operator.

    So, in your original expression you specify that every div[@class='listing_content'] element that is the i-th child of its parent should be selected.

    However, in the XML document you are working with, every div[@class='listing_content'] happens to be the first (and only) child of its parent — therefore if i > 1 then nothing is selected.

    As in any other language, in order to override the default priority, we must use brackets.

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

Sidebar

Related Questions

What XPath query should I use to get to the GetLogisticsOfferDateResult Node? I have
I have this xpath query: descendant-or-self::link and this html code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta
I have this div: <div class=product-name>Product1</div> I also have this div: <div class=product-name gold>Product2</div>
I have an XML value and an XPath query like this: XML: <Firms> <Firm
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
If I have an XPath query like NodeA/NodeB[@WIDTH and not(@WIDTH=20)] | NodeC[@WIDTH and not(@WIDTH=20)]/NodeD
I have a html structure like this.. <div id=divid> <ul id=ulid> <li style=margin-left: 8px>
What am I doing wrong with this XPath query? Within the feed tag, there
My XPath is a little bit rusty... Let's say I have this simple XML
I have a very simple XML datasource structured like this: <datasource> <row> <column>Some text

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.