1
當我把一個點,使XPath的相對我的,它返回{「名」:「無」},當我刪除了點,直到循環結束XPath的相對路徑返回無
.//*[@id="listingAds"]/section/section/ul/li[1]/a/section/h2
重複相同的數據
下面是完整的代碼
import scrapy
class BrickSetSpider(scrapy.Spider):
name = "brickset_spider"
start_urls = ['https://www.leboncoin.fr/annonces/offres/bretagne/']
def parse(self, response):
SET_SELECTOR = '.dontSwitch .trackable'
for annonce in response.css(SET_SELECTOR):
NAME_SELECTOR = './/*[@id="listingAds"]/section/section/ul/li[1]/a/section/h2'
NAME_CATEGORIE = '.item_title+ .item_supp ::text'
NAME_PLACE = '.item_supp+ .item_supp ::text'
NAME_PRICE = '.item_price ::text'
yield {
'name': annonce.xpath(NAME_SELECTOR).extract_first(),
}