1

我正在尝试匹配网站中的元描述,但无法获取过去的 HTML 实体。我试过转义字符和其他一些组合。如果您尝试匹配没有实体的文本区域,则没有问题。任何帮助表示赞赏。

require "rubygems"
require "watir-webdriver"

include Watir

b = Watir::Browser.new :chrome

b.goto('http://dev01-new.firestonecompleteautocare.com/cf/oil-change/motor-oil-and-your-car')

if b.metas.any?{ |s| s.html.include? "Ever wonder what color your engine oil should 
be, or what affect temperature may have on it? Learn the answers to these 
frequently asked questions & more, here." }
     puts 'Yes'
else
     puts 'No'
end

b.close
4

1 回答 1

5

看起来 watir-webdriver 允许您根据其内容属性定位元。

所以你可以这样做:

b.meta(:content => 'Ever wonder what color your engine oil should be, or what affect temperature may have on it? Learn the answers to these frequently asked questions & more, here.').exists?
#=> true

请注意,在这里您可以使用实际字符而不用担心 HTML 编码。

于 2013-02-08T15:10:28.783 回答