Ruby 解析:我可以在Nokogiri中找到嵌入CSS背景的URL吗?

Ruby 解析:我可以在Nokogiri中找到嵌入CSS背景的URL吗?,ruby,parsing,screen-scraping,nokogiri,Ruby,Parsing,Screen Scraping,Nokogiri,我正在解析的HTML在表中包含带有内联CSS的图像,我可以使用Nokogiri确定URL组件是什么,下面是我要解析的代码片段: tldr:我想使用nokogiri获取这个html片段中的.png文件 <table border="0" cellspacing="0" cellpadding="0" width="300" height="300" background="http://s3.amazonaws.com/static.example.com/sale/homepage/316

我正在解析的HTML在表中包含带有内联CSS的图像,我可以使用Nokogiri确定URL组件是什么,下面是我要解析的代码片段:

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

<table border="0" cellspacing="0" cellpadding="0" width="300" height="300" background="http://s3.amazonaws.com/static.example.com/sale/homepage/3166-300x300-1328107072.png" style="background-image:url('http://s3.amazonaws.com/static.example.com/sale/homepage/3166-300x300-1328107072.png');background-repeat:no-repeat;background-color:#cacaca">
<tbody><tr>
<td>
<table background="http://s3.amazonaws.com/static.example.com/relaunch/transparent-strip1_1x1.png" style="background-image:url('http://s3.amazonaws.com/static.example.com/relaunch/transparent-strip1_1x1.png');background-repeat:repeat;background-color:transparent" border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td style="vertical-align:middle" width="260" height="60">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:13px;padding:2px 5px 0 10px;font-weight:bold;display:block;color:#ffffff">Kristins Gifts</span>
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px;padding:2px 5px 0 10px;line-height:16px;display:block;color:#ffffff">Stationery to Explore</span>
</td>
</tr>
</tbody></table>
</td>
<td>
<table background="http://s3.amazonaws.com/static.example.com/relaunch/transparent-strip1_1x1.png" style="background-image:url('http://s3.amazonaws.com/static.example.com/relaunch/transparent-strip1_1x1.png');background-repeat:repeat;background-color:transparent" border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td style="vertical-align:top;text-align:right" width="50" height="60">
<span style="display:block;padding:18px 16px 0 0"><a href="http://mailer.example.com/clzh.7n1p/Ty4bBi0W_QUigx74Be7d5" alt="Stationery to Explore" title="Stationery to Explore" style="display:inline-block;outline:none" target="_blank"><img src="http://s3.amazonaws.com/static.example.com/relaunch/sales-arrow-button.png" alt=" &gt; " height="23" width="23" style="border:0"></a></span>
</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td colspan="2" height="240">
<a href="http://mailer.example.com/clzh.7n1p/Ty4bBi0W_QUigx74C5096" alt="Stationery to Explore" title="Stationery to Explore" style="width:100%;min-height:240px;display:block;outline:none" target="_blank"></a>
</td>
</tr>
</tbody></table>

克里斯汀礼物
文具探索

在这种情况下,您不必查看CSS,您可以直接从
节点上的
背景属性中拉出图像:

>> 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

在这种情况下,您不必查看CSS,您可以直接从
节点上的
背景属性中拉出图像:

>> 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