-
Notifications
You must be signed in to change notification settings - Fork 161
Start requests #38
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
Merged
Merged
Start requests #38
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
32ef41b
skip failing test TODO investigate later
pawelmhm 2d4da86
[crawl_resource] allow url if start_requests=True
pawelmhm bbe85f3
add start_requests support
pawelmhm 005d76f
Merge branch 'master' into start_requests
pawelmhm a8c2b83
add test for spider with start_requests
pawelmhm a1fa6fd
[resources] refactor, rename important variable names
pawelmhm 50f496e
[style] sort imports in resources
pawelmhm 3b90103
[requirements-dev] update test packages to versions that
pawelmhm 0da27f2
[utils] add tests for extract_scrapy_request_args
pawelmhm abb4a2a
[crawler_manager_test] unskip limit runtime test
pawelmhm 5454bf3
[resources] more renaming of spider_Data to scrapy_request_args
pawelmhm 9c2f456
[tests] parametrize resource tests
pawelmhm a6ad46a
[resources] dont validate/register api parameters
pawelmhm b5ae65b
[docs] document start_requests parameter
pawelmhm 0c63621
[tests/test_resource_crawl] dont rely on item order in tests
pawelmhm 79e3e47
[tests] add test for scenario when start_requests and url present
pawelmhm 59d0a01
[resources] readability in start_requests POST handler
pawelmhm ebec1ae
[tests] add another test for POST handler
pawelmhm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| -r requirements.txt | ||
|
|
||
| fabric | ||
| requests | ||
| mock | ||
| pytest | ||
| pytest-cov | ||
| port-for | ||
| requests==2.9.1 | ||
| mock==1.3.0 | ||
| pytest==2.9.1 | ||
| pytest-cov==2.2.1 | ||
| port-for==0.3.1 |
This file contains hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| import inspect | ||
| from scrapy import Request | ||
|
|
||
|
|
||
| def extract_scrapy_request_args(dictionary, raise_error=False): | ||
| """ | ||
| :param dictionary: Dictionary with parameters passed to API | ||
| :param raise_error: raise ValueError if key is not valid arg for | ||
| scrapy.http.Request | ||
| :return: dictionary of valid scrapy.http.Request positional and keyword | ||
| arguments. | ||
| """ | ||
| result = dictionary.copy() | ||
| args = inspect.getargspec(Request.__init__).args | ||
| for key in dictionary.keys(): | ||
| if key not in args: | ||
| result.pop(key) | ||
| if raise_error: | ||
| msg = u"{!r} is not a valid argument for scrapy.Request.__init__" | ||
| raise ValueError(msg.format(key)) | ||
| return result | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,3 +4,5 @@ | |
|
|
||
| class TestprojectItem(scrapy.Item): | ||
| name = scrapy.Field() | ||
| referer = scrapy.Field() | ||
| response = scrapy.Field() | ||
23 changes: 23 additions & 0 deletions
23
tests/sample_data/testproject/testproject/spider_templates/testspider_startrequests.py
This file contains hidden or 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,23 @@ | ||
| # -*- coding: utf-8 -*- | ||
| import scrapy | ||
|
|
||
| from ..items import TestprojectItem | ||
|
|
||
|
|
||
| class TestSpider(scrapy.Spider): | ||
|
|
||
| name = 'test_with_sr' | ||
| initial_urls = ["{0}", "{1}"] | ||
|
|
||
| def start_requests(self): | ||
| for url in self.initial_urls: | ||
| yield scrapy.Request(url, callback=self.some_callback, meta=dict(referer=url)) | ||
|
|
||
| def some_callback(self, response): | ||
| name = response.xpath('//h1/text()').extract() | ||
| return TestprojectItem(name=name, referer=response.meta["referer"]) | ||
|
|
||
| def parse(self, response): | ||
| name = response.xpath("//h1/text()").extract() | ||
| return TestprojectItem(name=name, referer=response.meta.get("referer"), | ||
| response=response.url) |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| <html> | ||
|
|
||
| <head> | ||
| <title>Page 1</title> | ||
| <title>Page 2</title> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <h1>Page 1</h1> | ||
| <h1>Page 2</h1> | ||
|
|
||
| </body> | ||
| </html> |
This file contains hidden or 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,12 @@ | ||
| <html> | ||
|
|
||
| <head> | ||
| <title>Page 3</title> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <h1>Page 3</h1> | ||
|
|
||
| </body> | ||
| </html> |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea~~, what about rewriting it slightly?~~ + even short docstring is better than no docstring at all
UPD: probably you should ignore this snippet, see comment below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... unless
result.pop()was put in original version intentionally to split passed dictionary into spider data and request data. Please document this and let's keep version with.pop()There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added docstring and unit test for utility