限制scrapy抓取子域

Moi*_*ver 5 regex web-crawler scrapy python-3.x

我有大约 200 个域需要抓取,但我确定子域中不包含对我有用的信息,因此我想将它们从抓取中排除。

对于域 example.com,我可以使用拒绝规则

(www.)*\w+\.example
Run Code Online (Sandbox Code Playgroud)

但是这种方法会让我为每个域编写 200 条拒绝规则。我的问题是是否可以为每个域的所有子域创建拒绝规则?

来自蜘蛛的片段:

class Spider(CrawlSpider):
    name = "courses"
    start_urls = [
        'https://www.eb-zuerich.ch',
]

    allowed_domains = ['eb-zuerich.ch',]


    rules = [
    Rule(LinkExtractor(allow=(),
                       deny=(r'.+[sS]itemap', r'.+[uU]eber', r'.+[kK]ontakt', r'.+[iI]mpressum',
                        r'.+[lL]ogin', r'.+[dD]ownload[s]?', r'.+[dD]isclaimer',
                        r'.+[nN]ews', r'.+[tT]erm', r'.+[aA]nmeldung.+',
                        r'.+[Aa][Gg][Bb]', r'/en/*', r'\.pdf$')),
         callback='parse_item', follow=True)
]

    def parse_item(self, response):

        # get soup of the current page
        soup = bs(response.body, 'html.parser')
        page_soup = bs(response.body, 'html.parser')

        # check if it is a course description page
        ex = Extractor(response.url, soup, page_soup)
        is_course = ex.is_course_page()
        if is_course:
            ex.save_course_info()
Run Code Online (Sandbox Code Playgroud)

我正在使用 Scrapy 1.4.0 和 Python 3.6.1

Gal*_*cio 1

我的问题是是否可以为每个域的所有子域创建拒绝规则?

采用简单的方法(忽略顶级域名,例如.co.uk):

r'^(https?)?//([^./]+\.){2,}[^./]+(/|$)'