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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:22:09+00:00 2026-06-07T23:22:09+00:00

I am scraping a webpage for text, using the code as follows doc.xpath(//td[text()=’Operating system’]/following-sibling::td)

  • 0

I am scraping a webpage for text, using the code as follows

doc.xpath("//td[text()='Operating system']/following-sibling::td")
doc.xpath("//td[text()='Processors']/following-sibling::td")

I have about 30 of these so I thought I could maybe use an array but its not working, here is my code

clues = Array.new
clues << 'Operating system'
clues << 'Processors'
clues << 'Chipset'

clues.each do |clue_storeage|
doc.xpath("//td[text()=#{clues}]/following-sibling::td")
end

Is there a way I can feed the array into that loop and then output that to a CSV?

  • 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-07T23:22:11+00:00Added an answer on June 7, 2026 at 11:22 pm

    To clarify mb2nd’s comment, your each block is incorrectly referencing the array. This should work:

    clues.each do |clue|
      doc.xpath("//td[text()=#{clue}]/following-sibling::td")
    end
    

    To output the captured data to CSV you could run:

    csv = ""
    clues.each do |clue|
      csv << doc.xpath("//td[text()=#{clue}]/following-sibling::td")
      csv << ", " unless clues.last == clue
    end
    

    The doc.xpath(“//td[text()=#{clue}]/following-sibling::td”) call may need .value on the end?

    On a side note; you may also populate your array like so:

    clues = ['Operating system', 'Processors', 'Chipset']  
    

    EDIT (after last comment from @Ninja2K)

    You need to save the result of each the xpath calls. Here’s some working code:

    require 'rubygems' 
    require 'nokogiri' 
    require 'open-uri' 
    
    doc = Nokogiri::HTML(open("http://h10010.www1.hp.com/wwpc/ie/en/ho/WF06b/321957-321957-3329742-89318-89318-5186820-5231694.html?dnr=1%22"))
    
    clues = ['Operating system', 'Processors', 'Chipset'] 
    
    csv_text = ""
    clues.each do |clue|
      csv_text << doc.at_xpath("//td[text()='#{clue}']/following-sibling::td").text
      csv_text << ", " unless clues.last == clue
    end
    puts csv_text
    

    BTW. You may also find this article useful: http://hunterpowers.com/data-scraping-and-more-with-ruby-nokogiri-sinatra-and-heroku/

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

Sidebar

Related Questions

I did scraping text from webpage using scrapy. In spider, I have code like:
Scraping pages using BeautifulSoup; trying to filter out links that end in ...html#comments Code
I have made the following webpage for generating interactive todo lists: http://robert-kent.com/todo/todo.php Basically, the
I am using Selenium webdriver in Python for a web-scraping project. The webpage, I
I have started developing a webpage and recently hired someone to write code to
I´m all new to scraping and I´m trying to understand xpath using R. My
I am using Web-Harvest to do some web page scraping. I have a table
Scraping a webpage, containing about 250 table divisions. Using WatiN and WatinCSSSelectors First I
I have recently started using Web-Harvest as a web scraping tool. Currently, I am
I'm scraping a website that's mostly table based. I have <tr> tags that each

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.