Skip to content

Commit

Permalink
Merge pull request #29 from zytedata/fix-from-crawler
Browse files Browse the repository at this point in the history
fix `extract_from` spider parameter not working
  • Loading branch information
kmike authored Jan 26, 2024
2 parents 0cb9d92 + 1899409 commit 570edab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
31 changes: 31 additions & 0 deletions tests/test_ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ def test_arguments():
"getdict",
{"geolocation": "DE"},
),
(
"extract_from",
"browserHtml",
"ZYTE_API_PROVIDER_PARAMS",
None,
"getdict",
{
"productOptions": {"extractFrom": "browserHtml"},
"productNavigationOptions": {"extractFrom": "browserHtml"},
},
),
(
"extract_from",
"httpResponseBody",
"ZYTE_API_PROVIDER_PARAMS",
{"geolocation": "US"},
"getdict",
{
"productOptions": {"extractFrom": "httpResponseBody"},
"productNavigationOptions": {"extractFrom": "httpResponseBody"},
"geolocation": "US",
},
),
(
"extract_from",
None,
"ZYTE_API_PROVIDER_PARAMS",
{"geolocation": "US"},
"getdict",
{"geolocation": "US"},
),
):
kwargs = {param: arg}
settings = {}
Expand Down
8 changes: 7 additions & 1 deletion zyte_spider_templates/spiders/ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
from zyte_common_items import ProbabilityRequest, Product, ProductNavigation

from zyte_spider_templates.documentation import document_enum
from zyte_spider_templates.spiders.base import BaseSpider, BaseSpiderParams
from zyte_spider_templates.spiders.base import (
ARG_SETTING_PRIORITY,
BaseSpider,
BaseSpiderParams,
)


@document_enum
Expand Down Expand Up @@ -129,7 +133,9 @@ def from_crawler(cls, crawler: Crawler, *args, **kwargs) -> scrapy.Spider:
"productNavigationOptions": {
"extractFrom": spider.args.extract_from
},
**spider.settings.get("ZYTE_API_PROVIDER_PARAMS", {}),
},
priority=ARG_SETTING_PRIORITY,
)

return spider
Expand Down

0 comments on commit 570edab

Please sign in to comment.