ruby - Find a table containing specific text -
ruby - Find a table containing specific text -
i have table:
html =' <table cellpadding="1" cellspacing="0" width="100%" border="0"> <tr> <td colspan="9" class="csogreen"><b class="white">bill statement detail</b></td> </tr> <tr style="background-color: #d8e4f6;vertical-align: top;"> <td nowrap="nowrap"><b>bill date</b></td> <td nowrap="nowrap"><b>bill amount</b></td> <td nowrap="nowrap"><b>bill due date</b></td> <td nowrap="nowrap"><b>bill (pdf)</b></td> </tr> </table> ' i utilize codes suggested in post (xpath matching text in table - ruby - nokigiri). works fine if utilize words in first row match word, illustration "statement". doesn't work if utilize words in other row, illustration "amount".
doc = nokogiri::html("#{html}") doc.xpath('//table[contains(descendant::*, "statement")]').each |node| puts node.text end
the contains() function expects singular value first argument. descendant::* may yield multiple elements causing function behave unexpectedly, such considering first element yielded.
try alter xpath be:
doc.xpath('//table[descendant::*[contains(., "amount")]]').each |node| puts node.text end ruby xpath nokogiri
Comments
Post a Comment