問題は、「start_urls」に直接商品URLを追加するとすべて正常に機能することです。しかし、製品ページをクロール(すべてのページに戻り「200」をクロール)それはこすっていません.... 中に表示されたとき、私はクモを通じ実行している:治療のクロールはこすりません
scrape crawl site_products -t csv -o Site.csv
スパイダーコード:
#-*- coding: utf-8 -*-
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from site.items import SiteItem
import datetime
class SiteProducts(CrawlSpider):
name = 'site_products'
allowed_domains = ['www.example.com']
start_urls = [
#'http://www.example.com/us/sweater_cod39636734fs.html',
#'http://www.example.com/us/sweater_cod39693703uh.html',
#'http://www.example.com/us/pantaloni-5-tasche_cod36883777uu.html',
#'http://www.example.com/fr/robe_cod34663996xk.html',
#'http://www.example.com/fr/trousers_cod36898044mj.html',
'http://www.example.com/us/women/onlinestore/suits-and-jackets',
]
rules = (
# Extract links matching 'item.php' and parse them with the spider's method parse_item
Rule(LinkExtractor(allow=('http://www.example.com/us/', 'http://www.example.com/fr/',)), follow=True),
Rule(LinkExtractor(allow=('.*_cod.*\.html',)), callback='parse_item'),
)
def parse_item(self, response):
self.logger.info('Hi, this is an item page! %s', response.url)
item = SiteItem()
item['name'] = response.xpath('//h2[@class="productName"]/text()').extract()
item['price'] = response.xpath('//span[@class="priceValue"]/text()')[0].extract()
if response.xpath('//span[@class="currency"]/text()')[0].extract() == '$':
item['currency'] = 'USD'
else:
item['currency'] = response.xpath('//span[@class="currency"]/text()')[0].extract()
item['category'] = response.xpath('//li[@class="selected leaf"]/a/text()').extract()
item['sku'] = response.xpath('//span[@class="MFC"]/text()').extract()
if response.xpath('//div[@class="soldOutButton"]/text()').extract() == True or response.xpath('//span[@class="outStock"]/text()').extract() == True:
item['avaliability'] = 'No'
else:
item['avaliability'] = 'Yes'
item['time'] = datetime.datetime.now().strftime("%Y.%m.%d %H:%M")
item['color'] = response.xpath('//*[contains(@id, "color_")]/a/text()').extract()
item['size'] = response.xpath('//*[contains(@id, "sizew_")]/a/text()').extract()
if '/us/' in response.url:
item['region'] = 'US'
elif '/fr/' in response.url:
item['region'] = 'FR'
item['description'] = response.xpath('//div[@class="descriptionContent"]/text()')[0].extract()
return item
を私は何が欠けていますか?
すでにこれをsettings.pyで行っています。すべてのページでCrawled(200)になっています。しかし、私が上で言ったように、私はまだ0スクレープを得ています。しかし、 "start_urls"に製品URLを追加すると、正確な製品をすこぶるように掻き集めることになります。 –
@ LeonidIvanov私はあなたのスパイダーを試しましたが、それは動作しますが、あなたの最初のlinkextractorが製品の抽出をブロックしているようです。 – Granitosaurus
ありがとうございます!それは助けになった!問題は何かを把握するために一日中忘れてしまいました....ところで、それは「否定」ではなく「否定」です。 –