2017-04-25 34 views
0

我正在嘗試scrapy的規則/鏈接提取器。回叫沒有在scrapy中調用

「restrict_css」下的css是正確的,我可以在scrapy shell中檢索使用response.css的鏈接,但是由於某種原因,當我在蜘蛛uner規則和鏈接提取器中運行這個函數時,並沒有調用parse_product回調函數。

rules=(
    Rule(LinkExtractor(restrict_css='a.i-next')), 

    Rule(LinkExtractor(restrict_css='div.product-image-wrapper>a'), 
     callback='parse_product'), 
) 

def parse_product(self, response): 

    print("Print anything for testing") 
    return 

謝謝,任何幫助,將不勝感激。

+0

你在爬行什麼頁面? – Granitosaurus

+0

allowed_domains = ['http://www.orsay.com/de-de/'] start_urls = ['http://www.orsay.com/de-de/'] –

回答

0

您的start_urls匹配任何規則。第一條規則是針對下一頁,第二條規則是針對產品的?但您的開始網址並未指向產品類別,只是着陸頁。您或者需要直接從產品詳情頁面網址開始,如:http://www.orsay.com/de-de/neuheiten/t-shirts/tops.html

或者添加其他規則以查找產品詳情頁面。

+0

感謝幫助。愚蠢的錯誤:) –

+0

@AhmadAshraf偉大的,不要忘了點擊接受答案左側的答案,如果你有你的問題解決:) – Granitosaurus