【发布时间】:2019-07-11 12:28:23
【问题描述】:
基本的蜘蛛工作。 然后我将它转换为 CrawlSpider 和规则,不幸的是现在蜘蛛不再工作了。
基本蜘蛛在产品详细信息页面上进行测试: https://www.ah.nl/producten/product/wi395939/ah-kleintje-boerenkool 然后它获取指定的项目。
我的兴趣是使用 CrawlSpider 浏览所有奖励文章https://www.ah.nl/bonus 转到产品详细信息页面并获取指定信息。
如何修复我的代码以使蜘蛛再次工作?
谁能解释我在规则方面做错了什么
我也想排除 response.xpath("//div[contains(@class,'product-sidebar__products')]") 如果此“anderen kochten ook”(英文:“other customers both these products”)出现在产品详细信息页面上 https://www.ah.nl/producten/product/wi160917/ah-verse-pesto-groen 在这里 https://www.ah.nl/producten/product/wi220252/swiffer-vloerreiniger-navul-stofdoekjes这里不存在
我尝试了很多事情,但无法理解规则
class ahSpider(CrawlSpider):
name = 'ah'
allowed_domains = ['ah.nl'] # geen url neer zetten alleen domain name
start_urls = ['https://www.ah.nl']
# "anderen kochten ook" "in English: “other customers both these products"
# response.xpath("//div[contains(@class,'product-sidebar__products')]")
rules = [
Rule(LinkExtractor(allow=('/bonus'), deny=('/allerhandebox/', '/allerhande/', '/winkels/', '/acties/', '/klantenservice/', '/zakelijk/', '/bezorgbundel/', '/vakslager/')), follow=True),
Rule(LinkExtractor(allow=('/producten/product/[0-9]+/[0-9]+'),), callback='parse_items'),
]
#def parse(self, response):
def parse_items(self, response):
items = AhItem()
product_name = response.xpath("//span[contains(@class, 'line-clamp--active')]//text()").extract_first()
items['product_name'] = product_name
yield items
【问题讨论】:
-
您好,欢迎您。
doesn't work anymore永远不会自我解释。你得到什么错误?或者结果是什么?它与您的预期有何不同?您应该编辑您的问题并添加更多信息,以便更好地获得快速和相关的答案。此外,请避免在一个问题中提出多个问题:使用单独的帖子。在 SO 上玩得开心。