小编ale*_*nio的帖子

Scrapy LinkExtractor - 限制每个 URL 抓取的页面数量

我试图在 Scrapy 的 CrawlSpider 中限制每个 URL 抓取的页面数。我有一个 start_urls 列表,我想对每个 URL 中正在抓取的页面数量设置限制。一旦达到限制,蜘蛛应该移动到下一个 start_url。

我知道设置中有 DEPTH_LIMIT 参数,但这不是我要找的。

任何帮助都会有用。

这是我目前拥有的代码:

class MySpider(CrawlSpider):
    name = 'test'
    allowed_domains = domainvarwebsite
    start_urls = httpvarwebsite

    rules = [Rule(LinkExtractor(),
             callback='parse_item',
             follow=True)
            ]

    def parse_item(self, response):
        #here I parse and yield the items I am interested in.
Run Code Online (Sandbox Code Playgroud)

编辑

我试图实现这一点,但我得到 exceptions.SyntaxError: invalid syntax (filter_domain.py, line 20). 关于发生了什么的任何想法?

再次感谢。

filter_domain.py

import urlparse
from collections import defaultdict
from scrapy.exceptions import IgnoreRequest

class FilterDomainbyLimitMiddleware(object):
def __init__(self, domains_to_filter):
    self.domains_to_filter = domains_to_filter
    self.counter = …
Run Code Online (Sandbox Code Playgroud)

python web-crawler limit scrapy

7
推荐指数
1
解决办法
2519
查看次数

SQL - 检查多个表中是否存在记录

我一直在堆栈中搜索类似的问题,但我找不到一个帮助我解决这个问题,或者我无法理解它.我有3张桌子.

Users
+---------+------+--------------+
| id_user | name | age          |
+---------+------+--------------+
| user1   | John | 51           |
+---------+------+--------------+
| user2   | Jane | 65           |
+---------+------+--------------+
| user3   | Katie| 51           |
+---------+------+--------------+
| user4   | Marck| 65           |
+---------+------+--------------+


City1
+---------+------+--------------+
| id_user | time | street       |
+---------+------+--------------+
| user1   | 8    | 111111111111 |
+---------+------+--------------+
| user2   | 5    | 222222222222 |
+---------+------+--------------+

City2
+---------+------+--------------+
| user_id | time | street       |
+---------+------+--------------+
| user1   | …
Run Code Online (Sandbox Code Playgroud)

mysql sql multiple-tables

1
推荐指数
1
解决办法
3973
查看次数

标签 统计

limit ×1

multiple-tables ×1

mysql ×1

python ×1

scrapy ×1

sql ×1

web-crawler ×1