-1
下面是HTML,我的工作:如何使用Scrapy的css或xpath選擇器來選擇ul的特定li子文本?
<div class="grdcpnsmllnks">
<ul>
<li><i class="fa fa-check-square"></i>Verified Offer</li>
<li><i class="fa fa-eye"></i><label id="ltveri276270">Offer used 1 hour ago</label></li>
<li><i class="fa fa-clock-o"></i>Valid till 31/12/2016</li>
</ul>
</div>
下面是我的代碼片段:
def parse_item(self, response):
endDate = response.xpath('//div[@class='grdcpnsmllnks']/ul/li/i[@class='fa-clock-o']::dd[1]/text()').extract()
yield {
'endDate': endDate
}
我要選擇的文本有效期至31/12/2016。我在首先選擇所需的<li>
標籤時遇到問題,然後進一步選擇不包含在任何標籤內的文本。請建議我如何使用xpath或css選擇器來做到這一點。
當我在.extract()中使用上面的命令時,它給出了一個屬性錯誤:'unicode'對象沒有屬性'extract()' –
@AmanAgarwal它已經被're_first()提取'不需要調用額外'提取()'。 – alecxe
但即便如此,它並沒有給予價值,而是給予了「無」。 –