Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrapy yield Request not working

Tags:

scrapy

I wrote the following scrapy spider but it's not continuing the crawling process after the initial request, although I've yielded more scrapy.Requests for scrapy to follow.

import regex as re
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import Spider

class myspider(Spider):
name = 'haha'

allowed_domains = ['https://blog.scrapinghub.com/']
start_urls = ['https://blog.scrapinghub.com/']
extractor = LinkExtractor(allow=allowed_domains)

def parse(self, response):
    # To extract all the links on this page
    links_in_page = self.extractor.extract_links(response)

    for link in links_in_page:
        yield scrapy.Request(link.url, callback=self.parse)
like image 386
Jianxin Gao Avatar asked Sep 09 '26 06:09

Jianxin Gao


1 Answers

allowed_domains needs to be a list of domains, not a list of URLs.

So it should be:

allowed_domains = ['blog.scrapinghub.com']
like image 79
paul trmbrth Avatar answered Sep 13 '26 01:09

paul trmbrth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!