3
<table>
  <tr>
    <td>hello</td>
    <td><img src="xyz.png" width="100" height="100"></td>
  </tr>
</table>



tabledata.rows.each do |row|
  row.cells.each do |cell|
    puts cell.text          
  end
end
puts "end"      

出力の取得 ->

hello
end

このような出力のために私は何をすべきですか - >

hello
xyz.png
end

のこぎりを使わずに。

4

1 に答える 1

8

属性の取得

Element#attribute_valueメソッドを使用して要素の属性を取得できます。例えば、

element.attribute_value('attribute')

多くの標準属性については、次のこともできます。

element.attribute

セル テキストまたはイメージ テキストを出力する

セルにテキストまたは画像があると仮定すると、次のようになります。

  1. セルを反復処理できます
  2. 画像が存在するかどうかを確認する
  3. 存在する場合は画像 src を出力します
  4. それ以外の場合は、セルのテキストを出力します

これは次のようになります。

tabledata.rows.each do |row|
  row.cells.each do |cell|
    if cell.image.exists?
      puts cell.image.src    #or cell.image.attribute_value('src')
    else
      puts cell.text
    end    
  end
end
puts "end" 
于 2013-04-13T12:14:32.057 に答える