-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from machinia/base-spider
Base Spider class
- Loading branch information
Showing
8 changed files
with
105 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ __pycache__ | |
*.egg-info | ||
build/ | ||
dist/ | ||
.coverage* | ||
.eggs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from abc import ABC, abstractmethod | ||
from urllib.parse import urlparse | ||
from scrapy import Spider | ||
from scraper_factory.core.utils import validate_url | ||
|
||
|
||
class BaseSpider(ABC, Spider): | ||
|
||
def __init__(self, name, uri, queue, **kwargs): | ||
if not validate_url(uri): | ||
raise ValueError('Invalid URL') | ||
|
||
self.name = name | ||
parsed_url = urlparse(uri) | ||
self.start_urls = [uri] | ||
self.base_url = parsed_url.scheme + '://' + parsed_url.netloc | ||
self.allowed_domains = [] | ||
self.allowed_domains.append(parsed_url.netloc) | ||
self.allowed_domains.append(uri.split('//')[-1]) | ||
|
||
self.q = queue | ||
super().__init__(**kwargs) | ||
|
||
@abstractmethod | ||
def parse(self, response): | ||
"""This method should implement how to parse the | ||
response data.""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters