Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new utils #17

Open
gustavorps opened this issue Sep 14, 2017 · 0 comments
Open

new utils #17

gustavorps opened this issue Sep 14, 2017 · 0 comments

Comments

@gustavorps
Copy link
Contributor


def url_is_from_any_domain(url, domains):
    """Return True if the url belongs to any of the given domains"""
    """Reference: https://github.com/scrapy/scrapy/blob/7e8453cf1ec992e5df5cebfeda08552c58e7c9bc/scrapy/utils/url.py#L28"""
    host = parse_url(url).netloc.lower()
    if not host:
        return False
    domains = [d.lower() for d in domains]
    return any((host == d) or (host.endswith('.%s' % d)) for d in domains)

def url_is_from_a_spider(url, spider):
    """Return True if the url belongs to the given spider"""
    return url_is_from_any_domain(url,
        [spider.name] + list(getattr(spider, 'allowed_domains', [])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant