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

  • Home
  • SEARCH
  • 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 9222693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:53:35+00:00 2026-06-18T03:53:35+00:00

What I need Execute Nokogiri query, add a line break so when data is

  • 0

What I need

Execute Nokogiri query, add a line break so when data is outputted its not bunched up.

data = doc.css('div#specifications div#spec-area ul.product-spec')[0].text 

I tried this

data = doc.css('div#specifications div#spec-area ul.product-spec')[0].css('li').each{ |li| li.replace '\n' }.text 

My Full Code

require 'Nokogiri'
require 'open-uri'
require 'spreadsheet'

doc = Nokogiri::HTML(open("http://www.asus.com/Notebooks_Ultrabooks/ASUS_TAICHI_21/#specifications"))

#Grab our product specifications - we only need the text not HTML
data = doc.css('div#specifications div#spec-area ul.product-spec')[0].text 

#Create the Spreadsheet
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet::Workbook.new

sheet1 = book.create_worksheet
sheet1.name = 'My First Worksheet'

#Output our data  to the Spreadsheet
sheet1[0,0] = data
book.write 'C:/Users/Barry/Desktop/output.xls'
  • 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-18T03:53:37+00:00Added an answer on June 18, 2026 at 3:53 am

    You don’t want to replace the list elements, you just want to map them to their texts and then join them together separated by newlines.

    If you grab the elements with this:

    data = doc.css('div#specifications div#spec-area ul.product-spec li')
    

    Then you can get a list of all the list elements separated by linebreaks using map and join, like this:

    lines = data.map(&:text).join("\n")
    

    (From the comments) I’ve never used ruby spreadsheet before, but this should allow you to input the data:

    data = doc.css('div#specifications div#spec-area ul.product-spec li')
    data.each_with_index { |line, i| sheet1[i,0] = line.text }
    

    Hope that helps.

    p.s. “nokogiri” in require "nokogiri" should be all lowercase.

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

Sidebar

Related Questions

I need to execute a query To retrieve data from multiple tables but I'm
I need to execute MDX query from command line (MS AS 2005). I have
I need execute an SQL query in ORACLE it takes a certain amount of
I need to execute a SQL Query between two databases. Example: SELECT * from
I need to execute ETL operation on large data package using spring integration. For
I need to execute a SELECT query with one variable (in the WHERE clause)
I need to execute a command line from a .NET windows application. I tried
I need execute 2 select in SQLAlchemy. For example: select1 = Session.query(col1, col2, col3,
I need to execute a program and retrieve its stdout output in c++. I'd
I need to execute a shell command from my .NET application, not unlike os.execute

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.