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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:12:16+00:00 2026-06-16T07:12:16+00:00

I am trying to get my Xpath query to output to new cell rows

  • 0

I am trying to get my Xpath query to output to new cell rows but I have not been successful.I am trying to get my output into colum A row by row instead of Row 1 Column A, B, C

My full code is at https://gist.github.com/3205801

Would it be best to use Axslx for this or is CSV the standard?

#Set encoding options to remove nasty Trademark symbols
  encoding_options = {
    :invalid           => :replace,  # Replace invalid byte sequences
    :undef             => :replace,  # Replace anything not defined in ASCII
    :replace           => '',        # Use a blank for those replacements
    :universal_newline => true       # Always break lines with \n
  }

doc = Nokogiri::HTML(open("http://h10010.www1.hp.com/wwpc/ie/en/ho/WF06b/321957-321957-3329742-89318-89318-5186820-5231694.html?dnr=1"))
#For each break create a ;
doc.css('br').each{ |br| br.replace ';' }

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

CSV.open("output.csv", "wb") do |csv|
  #1. Output the Clues header
  #2. Scrape the output/force encoding to remove special characters
    csv << clues
    csv << clues.map{|clue| doc.at("//td[text()='#{clue}']/following-sibling::td").text.strip.encode Encoding.find('ASCII'), encoding_options}
  #end loop
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-16T07:12:18+00:00Added an answer on June 16, 2026 at 7:12 am

    I am not sure I understand the question but I think you want the data like this:

    header1,value1
    header2,value2
    header3,value3
    

    rather than:

    header1,header2,header3
    value1,value2,value3
    

    If this is true you can do:

    CSV.open("output.csv", "wb") do |csv|
      clues.each do |one_clue|
        csv << one_clue
        xpath = "//td[text()='#{one_clue}']/following-sibling::td"
        csv << doc.at(xpath).text.strip.encode Encoding.find('ASCII'), encoding_options
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have an XPath query like NodeA/NodeB[@WIDTH and not(@WIDTH=20)] | NodeC[@WIDTH and not(@WIDTH=20)]/NodeD
I'm having a problem formating an xpath query. I'm trying to get products that
I have been trying to get my head around how simplexml and dom updates
I'm trying to query XML through XPATH but is having problem getting id() to
iam trying to get all object's xpath's from loaded page via selenium something similar
I'm trying to get the plain text from a word document. Specifically, the xpath
I'm trying to figure out two things: Can Xpath be used to query a
I'm trying to get the value of a hidden form with xpath, there are
I am currently trying the following xpath //tr[normalize-space(td/text())='User Name'] to get all the tr
I'm using xpath to query my xml for result items that have the name

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.