Watir object processing performance issue. How to make a Nokogiri html table into an array?

The following works, but always very slow, apparently stop my cleaning program and the Firefox or Chrome browser for whole minutes on the page:

pp recArray = $browser.table(:id,"recordTable").to_a

Getting text from an HTML table or html source is quick:

htmlcode = $browser.table(:id,"recordTable").html  # .text shows only plaintext portion like lynx

How can I create the same recArray (each element of <TR>) using, for example, a Nokogiri object containing only an html table?

recArray = Nokogiri::HTML(htmlcode).

+3
source share
3 answers

Do you want every tr in the table?

Nokogiri::HTML($browser.html).css('table[@id="recordTable"] > tr')

This gives a NodeSet, which may be more useful than Array. Of course there is still to_a

+2
source

, :

, , , Watir:: Webdriver Table #to_a, :

 recArray = Nokogiri::HTML(htmlcode). **??**

, , :

  recArray=$browser.table(:class, 'detail-table w-Positions').to_a

html Nokogiri, :

  recArray=Nokogiri::HTML($browser.html).css('table[@class="detail-table w-Positions"] tr').to_a 

, , .

, Nokogiri (Table Row?), , .join(",") ( .CSV , )

, , Ruby String, , html-:

 recArray= recArray.map {|row| row.css("td").map {|c| c.text}.to_a }  # Could of course be merged with above to even longer, nastier one-liner

Nokogiri, .text.

.

, , #to_a Watir:: Webdriver Table Ruby....

( , 100% , . .lib.rb).

+1

All Articles