0

Hello, anyone can help me with parsing an html table data to be saved directly in an excel file from the same parsing app?

2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by Taywin
0

What do you mean by that? You mean using a ruby script to read data from a HTML file, and then create an excel file from it? To read in a HTML file, you simply open the file and read the content using File class. To parse it, you could simply use scan() method of String class (could do it in many ways). Then to create an excel file (regardless the format), you could use SpreadSheet plug-in.

0

for your version I need to have the html file saved locally? i wanted to pass the url to the script and then make it fetch the data to be stored.

0

If you want to fetch directly from a URL, you need 'net/http' module to handle the connection & retrieve the HTML page data from the selected URL. The return value would be string.

=begin
i.e.
require "net/http"
domain = "www.adomain.com"
page = "/asub/page.html
http = Net::HTTP.new(domain, 80)
data = http.get(page, nil)  # page content
body = page_data.body  # this is the whole HTML string
=end

Then you deal with the string the same way you deal with the content read from a file. There is nothing different here.

Edited by Taywin

0

Err fixing my script above... The correct version should be as follows:

require "net/http"
domain = "www.adomain.com"
page = "/asub/page.html"
http = Net::HTTP.new(domain, 80)
data = http.get(page, nil)  # page content
body = data.body  # this is the whole HTML string
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.