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

Full crawl by default, reword strategies #40

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions tests/test_ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def test_parameters():


def test_start_requests():
crawler = get_crawler()
url = "https://example.com"
spider = EcommerceSpider(url=url)
spider = EcommerceSpider.from_crawler(crawler, url=url)
requests = list(spider.start_requests())
assert len(requests) == 1
assert requests[0].url == url
Expand Down Expand Up @@ -356,7 +357,7 @@ def test_metadata():
"param_schema": {
"properties": {
"crawl_strategy": {
"default": "navigation",
"default": "full",
"title": "Crawl strategy",
"description": "Determines how the start URL and follow-up URLs are crawled.",
"type": "string",
Expand All @@ -367,13 +368,18 @@ def test_metadata():
"title": "Full",
},
"navigation": {
"description": "Follow pagination, subcategories, and product detail pages.",
"description": (
"Follow pagination, subcategories, and "
"product detail pages. Pagination Only is a "
"better choice if the target URL does not "
"have subcategories, or if Zyte API is "
"misidentifying some URLs as subcategories."
),
"title": "Navigation",
},
"pagination_only": {
"description": (
"Follow pagination and product detail pages. SubCategory links are ignored. "
"Use this when some subCategory links are misidentified by ML-extraction."
"Follow pagination and product detail pages. Subcategory links are ignored."
),
"title": "Pagination Only",
},
Expand Down
23 changes: 15 additions & 8 deletions zyte_spider_templates/spiders/ecommerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ class EcommerceCrawlStrategy(str, Enum):
extract as many products as possible."""

navigation: str = "navigation"
"""Follow pagination, subcategories, and product detail pages."""
"""Follow pagination, subcategories, and product detail pages.

Pagination Only is a better choice if the target URL does not have
subcategories, or if Zyte API is misidentifying some URLs as subcategories.
"""

pagination_only: str = "pagination_only"
"""Follow pagination and product detail pages. SubCategory links are
ignored. Use this when some subCategory links are misidentified by
ML-extraction."""
"""Follow pagination and product detail pages. Subcategory links are
ignored."""


class EcommerceSpiderParams(BaseSpiderParams):
crawl_strategy: EcommerceCrawlStrategy = Field(
title="Crawl strategy",
description="Determines how the start URL and follow-up URLs are crawled.",
default=EcommerceCrawlStrategy.navigation,
default=EcommerceCrawlStrategy.full,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concern that Konstantin has raised is that this might put the spotlight in another issue which is the duplicate product URLs crawled with varying URL Query parameters. In any case, we already have a POC made for it which would work without any configuration/intervention at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another concern that Konstantin has raised would be if we might change to another default crawl_strategy in the future. Perhaps when the subCategory link misclassification has been addressed. This could cause another set of changes to the spider.

I think crawl_strategy=full as the default would be okay here (moving forward) since users are most likely to use the homepage as the seed URL input. The current crawl_strategy=navigation as the default would most likely cause some mistakes on the intended crawl behavior.

If they want to crawl a specific category, I think users would be more careful and aware of the crawl_strategy since they would specifically pick the category URL they want to crawl, putting more attention on it.

json_schema_extra={
"enumMeta": {
EcommerceCrawlStrategy.full: {
Expand All @@ -46,13 +49,17 @@ class EcommerceSpiderParams(BaseSpiderParams):
},
EcommerceCrawlStrategy.navigation: {
"title": "Navigation",
"description": "Follow pagination, subcategories, and product detail pages.",
"description": (
"Follow pagination, subcategories, and product detail "
"pages. Pagination Only is a better choice if the "
"target URL does not have subcategories, or if Zyte "
"API is misidentifying some URLs as subcategories."
),
},
EcommerceCrawlStrategy.pagination_only: {
"title": "Pagination Only",
"description": (
"Follow pagination and product detail pages. SubCategory links are ignored. "
"Use this when some subCategory links are misidentified by ML-extraction."
"Follow pagination and product detail pages. Subcategory links are ignored."
),
},
},
Expand Down
Loading