Skip to content

Commit

Permalink
Merge pull request #100 from scrapy-plugins/more-data-types
Browse files Browse the repository at this point in the history
Support more data types in the provider
  • Loading branch information
kmike authored Jul 12, 2023
2 parents fd91fbf + 7ac7f12 commit bd4bd6b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Requirements
* Python 3.7+
* Scrapy 2.0.1+

scrapy-poet integration requires more recent software:

* Python 3.8+
* Scrapy 2.6+

Installation
============
Expand Down Expand Up @@ -859,6 +863,11 @@ The currently supported dependencies are:
* ``web_poet.BrowserHtml``
* ``web_poet.BrowserResponse``
* ``zyte_common_items.Product``
* ``zyte_common_items.ProductList``
* ``zyte_common_items.ProductNavigation``
* ``zyte_common_items.Article``
* ``zyte_common_items.ArticleList``
* ``zyte_common_items.ArticleNavigation``

The provider will make a request to Zyte API using the ``ZYTE_API_KEY`` and
``ZYTE_API_URL`` settings. It will ignore the transparent mode and parameter
Expand Down
29 changes: 26 additions & 3 deletions scrapy_zyte_api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from scrapy.utils.defer import maybe_deferred_to_future
from scrapy_poet import PageObjectInputProvider
from web_poet import BrowserHtml, BrowserResponse
from zyte_common_items import Product
from zyte_common_items import (
Article,
ArticleList,
ArticleNavigation,
Product,
ProductList,
ProductNavigation,
)

from scrapy_zyte_api.responses import ZyteAPITextResponse

Expand All @@ -20,7 +27,16 @@
class ZyteApiProvider(PageObjectInputProvider):
name = "zyte_api"

provided_classes = {BrowserResponse, BrowserHtml, Product}
provided_classes = {
BrowserResponse,
BrowserHtml,
Product,
ProductList,
ProductNavigation,
Article,
ArticleList,
ArticleNavigation,
}

def __init__(self, injector):
super().__init__(injector)
Expand All @@ -47,7 +63,14 @@ async def __call__(
return results

html_requested = BrowserResponse in to_provide or BrowserHtml in to_provide
item_keywords = {Product: "product"}
item_keywords = {
Product: "product",
ProductList: "productList",
ProductNavigation: "productNavigation",
Article: "article",
ArticleList: "articleList",
ArticleNavigation: "articleNavigation",
}

zyte_api_meta = {}
if html_requested:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"provider": [
"scrapy-poet>=0.9.0",
"web-poet>=0.13.0",
"zyte-common-items",
"zyte-common-items>=0.7.0",
]
},
classifiers=[
Expand Down

0 comments on commit bd4bd6b

Please sign in to comment.