我正在使用scrapy外殼來提取一些文本數據。以下是我在scrapy外殼上給出的命令:Scrapy response.xpath不返回任何查詢
>>> scrapy shell "http://jobs.parklandcareers.com/dallas/nursing/jobid6541851-nurse-resident-cardiopulmonary-icu-feb2015-nurse-residency-requires-contract-jobs"
>>> response.xpath('//*[@id="jobDesc"]/span[1]/text()')
[<Selector xpath='//*[@id="jobDesc"]/span[1]/text()' data=u'Dallas, TX'>]
>>> response.xpath('//*[@id="jobDesc"]/span[2]/p/text()[2]')
[<Selector xpath='//*[@id="jobDesc"]/span[2]/p/text()[2]' data=u'Responsible for attending assigned nursi'>]
>>> response.xpath('//*[@id="jobDesc"]/span[2]/p/text()[preceding-sibling::*="Education"][following-sibling::*="Certification"]')
[]
第三個命令沒有返回任何數據。我試圖在命令中的2個關鍵字之間提取數據。我在哪裏錯了?
我在這個問題中有一個更多的小查詢。我試過這樣的東西:>>> jid = response.xpath('// * [@ id =「jobDesc」]/span [3]/text()')。extract()....我試過只提取數字並刪除「作業ID:」...但開始不會以同樣的方式工作..索引不在列表中 – Abhishek 2014-12-02 17:31:17
@crozzfire當然,這是['.re( )'](http://doc.scrapy.org/zh/latest/topics/selectors.html#using-selectors-with-regular-expressions),請參閱答案中的更新。 – alecxe 2014-12-02 18:05:16