无法使用scrapy创建scrapy德语网站

2024-10-05 12:18:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Scrapy进行网页抓取,成功创建了一个蜘蛛,它将抓取整个网站,包括具有相同域的内部链接,我使用了链接提取器来实现这一点。这种抓取在英语网站上很成功,但当我尝试抓取德语网站时,它不起作用,回调function parse_item()不会被调用。如果我将parse_item()更改为parse(),则会删除德国网站域URL,但不会删除内部链接。我该如何解决这个问题

下面是我的代码:

class WebSpider(CrawlSpider):

    name = 'WebSpider'
    
     #init function
     def __init__(self, *args, **kwargs):
         #code to accept domain url
         
        WebSpider.rules = [
                Rule(LinkExtractor(unique=True), callback='parse_item', follow=True)
            ]

        super(WebSpider, self).__init__(*args, **kwargs

     def parse_item(self, response):
         #Call back function to work with response

Tags: toselftrueparseinit网站链接response

热门问题