解析:我可以在Nokogiri中获取嵌入式CSS背景的URL吗?

我正在解析的HTML包含在表格中使用内联CSS的图像,我可以使用Nokogiri来确定URL组件,这里是我要解析的代码片段:

tldr:我想在这个html片段中使用nokogiri获取.png

Kristins Gifts Stationery to Explore
 >

在这种情况下,您不必查看CSS,您可以将图像从

节点上的background属性中拉出来:

 >> doc = Nokogiri::HTML(html) >> doc.css('table').each { |n| puts n[:background] } http://s3.amazonaws.com/static.example.com/sale/homepage/3166-300x300-1328107072.png http://s3.amazonaws.com/static.example.com/relaunch/transparent-strip1_1x1.png http://s3.amazonaws.com/static.example.com/relaunch/transparent-strip1_1x1.png