我正在尝试使用 XMLFeedSpider 解析 xml 提要
在 XML 提要中,我想提取“价格”项目:
<span class="price" id="product-price-2037">19,77 €</span>
但是这个价格项目在标签内的 html 代码中,如下所示:
<channel>
<item>
<title>
<![CDATA[ product title ]]>
</title>
<meta http-equiv="X-UA-Compatible" content="IE=8"/>
<link>http://example.com/apage.html</link>
<description>
<![CDATA[
<table><tr><td><a href="http://example.com/apage.html">
<img src="http://example.com/media/catalog/product/aimage173.jpg" border="0" align="left" height="75" width="75"></a></td>
<td style="text-decoration:none;"> <div class="price-bframe"> <p class="old-price"> <span class="price-label">Prix normal :</span>
<span class="price" id="old-price-2895037">40,00 €</span> </p>
<p class="special-price"> <span class="price-label">Prix spécial :</span>
<span class="price" id="product-price-2037">19,77 €</span> </p> </div> </td></tr></table>
]]>
</description>
</item>
</channel>
这是我的实际蜘蛛:
from scrapy.contrib.spiders import XMLFeedSpider
from scrapy.selector import XmlXPathSelector
from tutorial.items import DmozItem
class DmozSpider(XMLFeedSpider):
name = 'myspidername'
allowed_domains = ["example.com"]
start_urls = ['http://example.com/rss/catalog/new/store_id/1/']
iterator = 'iternodes'
itertag = 'channel'
def parse_node(self, response, node):
title = node.select('item/title/text()').extract()
link = node.select('item/link/text()').extract()
price = node.select('*[@class=price"]text()').extract()
item = DmozItem()
item['title'] = title
item['link'] = link
item['price'] = price
return item
结果 :
Invalid Xpath: *[@class=price"]text()