1
我想從這個website湊了一些數據,我的蜘蛛的代碼是:Python的XPath的選擇得到錯誤
# -*- coding: utf-8 -*-
import scrapy
from coder.items import CoderItem
# from scrapy.loader import ItemLoader
class LivingsocialSpider(scrapy.Spider):
name = "livingsocial"
allowed_domains = ["livingsocial.com"]
start_urls = (
'http://www.livingsocial.com/cities/15-san-francisco',
)
def parse(self, response):
# deals = response.xpath('//li')
for deal in response.xpath('//li/a//h2'):
item = CoderItem()
item['title'] = deal.xpath('text()').extract_first()
yield item
它工作得很好,但問題是,當我變成
for deal in response.xpath('//li'):
item = CoderItem()
item['title'] = deal.xpath('a//h2/text()').extract_first()
yield item
這,它沒有返回!這不應該是一樣的嗎?
謝謝,像魅力一樣工作:D – Mohib