How to get html table value efficiently into an array

M

mirthcyy

hi guys,

I have a table in html and I'm using watir rudy to read values from
that table and put into an array. Right now I'm doing like that:

frame.table:)id, "SomeTable").rows.each_with_index{|r, i|

totalcells=r.cells.length
j=1
while j<=totalcells do
$arrayResult.push(r.cell:)index,j).text)
j=j+1
end
}

But it's really slow. Is there any better way to do the cell loop and
is there any better way to save the cell values to an array instead of
push? Thanks a lot.
 
M

mirth

Just found out all I need to do is

$arrayResult=frame.table:)id, "SomeTable").to_a.flatten
 
P

Phlip

I have a table in html and I'm using watir rudy to read values from
that table and put into an array. Right now I'm doing like that:

frame.table:)id, "SomeTable").rows.each_with_index{|r, i| ....
....
}

But it's really slow.

That's because the r.cell is a complete ActiveX hit, which is expensive at this
resolution.

The fix is to use a method like table.inner_html to read the whole table into
memory. Then use REXML and XPath to scan the table. These operations all use
strings in memory, without ActiveX or IE in the loop, so they will be much faster.

(New question: Architecturally, why are you abusing Watir like this? It's for
spot-checking your output...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top