I'm using Nokogiri with Rails 5. How do I select either a "th" element or a "td" element from a table row? My goal is to get all the text of cells in a row (if there is a more generic, elegant solution, I'm all in). Here's what I have
text_all_rows = all_rows.map do |row|
row_values = row.css('td | th').map{|str| str.text }
.map{|str| str.gsub(/[[:space:]]+/, ' ').gsub(/Ap{Space}+|p{Space}+z/, '') }.join(" ")
[*row_values]
end
As you may have noticed "td | th" is not valid syntax for selecting the "th" or "td" elements from the row.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…