如何获取<;的src属性;img>;使用rubywatir标记
对于这样的输出,我应该怎么做->如何获取<;的src属性;img>;使用rubywatir标记,ruby,watir,Ruby,Watir,对于这样的输出,我应该怎么做-> hello end 不使用Nokogiri。获取属性 您可以使用element#attribute_value方法获取元素的属性。比如说, element.attribute\u值('attribute') 对于许多标准属性,还可以执行以下操作: element.attribute 输出单元格文本或图像文本 假设单元格包含文本或图像: 您可以遍历单元格 检查图像是否存在 输出图像src(如果存在) 否则输出单元格文本 这看起来像: hello xyz.png
hello
end
不使用Nokogiri。获取属性 您可以使用
element#attribute_value
方法获取元素的属性。比如说,
element.attribute\u值('attribute')
对于许多标准属性,还可以执行以下操作:
element.attribute
输出单元格文本或图像文本
假设单元格包含文本或图像:
hello
xyz.png
end
感谢AJcodez的编辑。现在看起来更清晰了。我如何将此图像以blob形式保存到数据库中@贾斯汀:你能澄清一下你所说的blob表单是什么意思吗?我的意思是,如果图像位于我的网页html上,我如何用watir将图像存储在blob字段中,rubyi尝试了这个方法,img=cell.image.src image=Net::HTTP.get_response(URI.parse(img)).body。它正在发挥作用。
hello
xyz.png
end
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"