[wtr-general] Re: Export entire html table to a text document

2011-12-02 Thread Mark Ballinger
Thank you for your reply.
After re-reading what I have written and thinking about what I what to
achieve... I don't believe I want to extract the table data into
excel. I would like to extract it to a .txt (notepad document).
The purpose of extracting the data is to check it against it against
what I have in my database :-). If I can get it into .txt file
(notepad document) I have the know-how to clean it and import it into
sql for validation.
FYI the data in the table looks like this...
table border=1 cellpadding=2trth Address /thth Council
tax band /thth Annual council tax /th/tr
trtd 2, STONELEIGH AVENUE, COVENTRY, CV5 6BZ /tdtd
align=center F /tdtd align=center pound;2125 /td/tr
... The above row is repeated many time ..
/table
Then the table is closed.
So to re-cap my situation. I can use Watir to navigate the browser to
the page containing the html table but my problem is that I am unsure
of how to extract the results (everything within the table tag -
including the html) to a .txt file and then save that .txt file onto
my computer.
I would prefer to take smaller steps with using Watir. I am knew to it
therefore I would just like to learn how to extract the table and save
everything that I have extracted into a .txt file. I have seen a
couple of examples online using hpricot. However most of the examples
seem to miss off code detailing how the array (if that is the correct
approach) is outputted into a .txt file.
Could you help by demonstrating how to write a simple piece of code
which will extract the html table ( and everything, including the
tr, td and everything in between) to a .txt notepad file?
Many thanks for your time.
On Dec 2, 2:36 am, bis bis...@gmail.com wrote:
 To me that sounds like a lot of extra work what happens once it is in an 
 excel? Why would putting it in an excel be better than asserting it all 
 within the test itself

 So I'll go ahead and ask some questions first.
 Will it happen more than once validating the excel?
 What sort of data is in the table?
 Would you be comparing the data in the excel vs data in a data base? If yes, 
 why not let the test do it?

 Sent from my iPhone

 On Dec 1, 2011, at 4:43 PM, Mark Ballinger mark.j.ballin...@gmail.com wrote:







  Hi I am a newbie to groups and to ruby, watir, watir-webdriver etc...

  Basically all I would like to do is export a table from a web page
  which I have instructed the browser to find using Watir-webdriver. I
  just want to take the whole contents of the html table and place it
  into Excel for further analysis.

  I have the got the following code to work:

  require 'rubygems'
  require 'hpricot'
  require watir-webdriver
  url = http://www.mycounciltax.org.uk/results?
  postcode=cv35+8ausearch=Search
  browser = Watir::Browser.new
  browser.goto url

  All i would like to do now is save the table. How do save the html to
  a csv or .txt file into my C;\Temp folder?

  Best Regards,

  Mark

  --
  Before posting, please readhttp://watir.com/support. In short: search 
  before you ask, be nice.

  watir-general@googlegroups.com
 http://groups.google.com/group/watir-general
  watir-general+unsubscr...@googlegroups.com

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


[wtr-general] Re: Export entire html table to a text document

2011-12-02 Thread orde
Although it won't capture the HTML tags, you can dump the contents of
a table like this:

table_contents = browser.table(:id, 'foo').to_a

For writing to .txt file, check out the ruby File class:
http://www.ruby-doc.org/core-1.9.3/File.html

This is an example for writing the HTML for a page to a file:

browser.goto(test_site)
html = browser.html

f = File.new(txt.txt, w+)
f.write(html)
f.close

Hope it helps.

orde

On Dec 2, 1:42 am, Mark Ballinger mark.j.ballin...@gmail.com wrote:
 Thank you for your reply.
 After re-reading what I have written and thinking about what I what to
 achieve... I don't believe I want to extract the table data into
 excel. I would like to extract it to a .txt (notepad document).
 The purpose of extracting the data is to check it against it against
 what I have in my database :-). If I can get it into .txt file
 (notepad document) I have the know-how to clean it and import it into
 sql for validation.
 FYI the data in the table looks like this...
 table border=1 cellpadding=2trth Address /thth Council
 tax band /thth Annual council tax /th/tr
 trtd 2, STONELEIGH AVENUE, COVENTRY, CV5 6BZ /tdtd
 align=center F /tdtd align=center pound;2125 /td/tr
 ... The above row is repeated many time ..
 /table
 Then the table is closed.
 So to re-cap my situation. I can use Watir to navigate the browser to
 the page containing the html table but my problem is that I am unsure
 of how to extract the results (everything within the table tag -
 including the html) to a .txt file and then save that .txt file onto
 my computer.
 I would prefer to take smaller steps with using Watir. I am knew to it
 therefore I would just like to learn how to extract the table and save
 everything that I have extracted into a .txt file. I have seen a
 couple of examples online using hpricot. However most of the examples
 seem to miss off code detailing how the array (if that is the correct
 approach) is outputted into a .txt file.
 Could you help by demonstrating how to write a simple piece of code
 which will extract the html table ( and everything, including the
 tr, td and everything in between) to a .txt notepad file?
 Many thanks for your time.
 On Dec 2, 2:36 am, bis bis...@gmail.com wrote:







  To me that sounds like a lot of extra work what happens once it is in an 
  excel? Why would putting it in an excel be better than asserting it all 
  within the test itself

  So I'll go ahead and ask some questions first.
  Will it happen more than once validating the excel?
  What sort of data is in the table?
  Would you be comparing the data in the excel vs data in a data base? If 
  yes, why not let the test do it?

  Sent from my iPhone

  On Dec 1, 2011, at 4:43 PM, Mark Ballinger mark.j.ballin...@gmail.com 
  wrote:

   Hi I am a newbie to groups and to ruby, watir, watir-webdriver etc...

   Basically all I would like to do is export a table from a web page
   which I have instructed the browser to find using Watir-webdriver. I
   just want to take the whole contents of the html table and place it
   into Excel for further analysis.

   I have the got the following code to work:

   require 'rubygems'
   require 'hpricot'
   require watir-webdriver
   url = http://www.mycounciltax.org.uk/results?
   postcode=cv35+8ausearch=Search
   browser = Watir::Browser.new
   browser.goto url

   All i would like to do now is save the table. How do save the html to
   a csv or .txt file into my C;\Temp folder?

   Best Regards,

   Mark

   --
   Before posting, please readhttp://watir.com/support. In short: search 
   before you ask, be nice.

   watir-general@googlegroups.com
  http://groups.google.com/group/watir-general
   watir-general+unsubscr...@googlegroups.com

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


Re: [wtr-general] Export entire html table to a text document

2011-12-02 Thread Željko Filipin
On Fri, Dec 2, 2011 at 1:43 AM, Mark Ballinger mark.j.ballin...@gmail.com
wrote:
 All i would like to do now is save the table.

Is this the same question?

http://stackoverflow.com/q/8355637/17469

Željko
--
watir.com/book - author

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com


[wtr-general] Re: Export entire html table to a text document

2011-12-02 Thread Chuck van der Linden
I'm writing this off the cuff so it might need a bit of debugging.

browser.table(:how = what).rows.each_with_index do |row, r|
  row.cells.each_with_index do |cell, c|
puts Row:#{r} Cell:#{c} text is: #{cell.text}
  end
end

if .rows or .cells does not work in the above, try replacing with .trs
and .tds respectively (not all versions of watir have the friendly
aliases for those)

See if that spits out what you are interested in.   If so, modify to
write what you want to a file instead of putting it to the screen..
Or better yet, you could put things into an array (using the index
values) and then iterate over the array comparing data from particular
cells with what's in the database.

You could probably even create your own 'table_text_to_array' method
which would accept a table object as input and return an array

There are some useful ruby gems for accessing databases, so it should
not be too hard (once you are clear about the format of the text in
the cells vs in your database) to verify the data presented in the web
UI matches the database

On Dec 2, 1:42 am, Mark Ballinger mark.j.ballin...@gmail.com wrote:
 Thank you for your reply.
 After re-reading what I have written and thinking about what I what to
 achieve... I don't believe I want to extract the table data into
 excel. I would like to extract it to a .txt (notepad document).
 The purpose of extracting the data is to check it against it against
 what I have in my database :-). If I can get it into .txt file
 (notepad document) I have the know-how to clean it and import it into
 sql for validation.
 FYI the data in the table looks like this...
 table border=1 cellpadding=2trth Address /thth Council
 tax band /thth Annual council tax /th/tr
 trtd 2, STONELEIGH AVENUE, COVENTRY, CV5 6BZ /tdtd
 align=center F /tdtd align=center pound;2125 /td/tr
 ... The above row is repeated many time ..
 /table
 Then the table is closed.
 So to re-cap my situation. I can use Watir to navigate the browser to
 the page containing the html table but my problem is that I am unsure
 of how to extract the results (everything within the table tag -
 including the html) to a .txt file and then save that .txt file onto
 my computer.
 I would prefer to take smaller steps with using Watir. I am knew to it
 therefore I would just like to learn how to extract the table and save
 everything that I have extracted into a .txt file. I have seen a
 couple of examples online using hpricot. However most of the examples
 seem to miss off code detailing how the array (if that is the correct
 approach) is outputted into a .txt file.
 Could you help by demonstrating how to write a simple piece of code
 which will extract the html table ( and everything, including the
 tr, td and everything in between) to a .txt notepad file?
 Many thanks for your time.
 On Dec 2, 2:36 am, bis bis...@gmail.com wrote:







  To me that sounds like a lot of extra work what happens once it is in an 
  excel? Why would putting it in an excel be better than asserting it all 
  within the test itself

  So I'll go ahead and ask some questions first.
  Will it happen more than once validating the excel?
  What sort of data is in the table?
  Would you be comparing the data in the excel vs data in a data base? If 
  yes, why not let the test do it?

  Sent from my iPhone

  On Dec 1, 2011, at 4:43 PM, Mark Ballinger mark.j.ballin...@gmail.com 
  wrote:

   Hi I am a newbie to groups and to ruby, watir, watir-webdriver etc...

   Basically all I would like to do is export a table from a web page
   which I have instructed the browser to find using Watir-webdriver. I
   just want to take the whole contents of the html table and place it
   into Excel for further analysis.

   I have the got the following code to work:

   require 'rubygems'
   require 'hpricot'
   require watir-webdriver
   url = http://www.mycounciltax.org.uk/results?
   postcode=cv35+8ausearch=Search
   browser = Watir::Browser.new
   browser.goto url

   All i would like to do now is save the table. How do save the html to
   a csv or .txt file into my C;\Temp folder?

   Best Regards,

   Mark

   --
   Before posting, please readhttp://watir.com/support. In short: search 
   before you ask, be nice.

   watir-general@googlegroups.com
  http://groups.google.com/group/watir-general
   watir-general+unsubscr...@googlegroups.com

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com