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

Replace example.com domains with Scrapinghub demo toscrape.com domains in the documentation #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions docs/intro/advanced-tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Suppose we have the following Page Object:

# Simulates clicking on a button that says "View All Images"
response: web_poet.HttpResponse = await self.http.get(
f"https://api.example.com/v2/images?id={item['product_id']}"
f"https://api.toscrape.com/v2/images?id={item['product_id']}"
Copy link
Member

Choose a reason for hiding this comment

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

This is not a working URL; is it possible to have a real example? I think the idea to use toscrape.com domain is to actually make the examples runnable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree @kmike . Though, the situation here is that we do not have a toscrape.com website that supports API calls. Now there are websites that support dummy/test API calls but the mandate of the issue was that we should not be using other external domains.

Can we setup an API based toscrape website?

Copy link
Member

@kmike kmike Jun 10, 2023

Choose a reason for hiding this comment

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

Not sure how it fits the example, but I think http://quotes.toscrape.com/scroll uses an AJAX call.

)
item["images"] = response.css(".product-images img::attr(src)").getall()
return item
Expand All @@ -85,8 +85,8 @@ It can be directly used inside the spider as:

def start_requests(self):
for url in [
"https://example.com/category/product/item?id=123",
"https://example.com/category/product/item?id=989",
"https://toscrape.com/category/product/item?id=123",
"https://toscrape.com/category/product/item?id=989",
]:
yield scrapy.Request(url, callback=self.parse)

Expand Down Expand Up @@ -128,7 +128,7 @@ This basically acts as a switch to update the behavior of the Page Object:
# Simulates clicking on a button that says "View All Images"
if self.page_params.get("enable_extracting_all_images")
response: web_poet.HttpResponse = await self.http.get(
f"https://api.example.com/v2/images?id={item['product_id']}"
f"https://api.toscrape.com/v2/images?id={item['product_id']}"
)
item["images"] = response.css(".product-images img::attr(src)").getall()

Expand Down Expand Up @@ -157,8 +157,8 @@ Let's see it in action:
}

start_urls = [
"https://example.com/category/product/item?id=123",
"https://example.com/category/product/item?id=989",
"https://toscrape.com/category/product/item?id=123",
"https://toscrape.com/category/product/item?id=989",
]

def start_requests(self):
Expand Down
12 changes: 6 additions & 6 deletions docs/rules-from-web-poet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ And then override it for a particular domain using ``settings.py``:
.. code-block:: python

SCRAPY_POET_RULES = [
ApplyRule("example.com", use=ISBNBookPage, instead_of=BookPage)
ApplyRule("toscrape.com", use=ISBNBookPage, instead_of=BookPage)
]

This new Page Object gets the original ``BookPage`` as dependency and enrich
Expand Down Expand Up @@ -211,7 +211,7 @@ Let's check out an example:
name: str


@handle_urls("example.com")
@handle_urls("toscrape.com")
@attrs.define
class ProductPage(WebPage[Product]):

Expand All @@ -225,7 +225,7 @@ Let's check out an example:

def start_requests(self):
yield scrapy.Request(
"https://example.com/products/some-product", self.parse
"https://toscrape.com/products/some-product", self.parse
)

# We can directly ask for the item here instead of the page object.
Expand All @@ -236,7 +236,7 @@ From this example, we can see that:

* Spider callbacks can directly ask for items as dependencies.
* The ``Product`` item instance directly comes from ``ProductPage``.
* This is made possible by the ``ApplyRule("example.com", use=ProductPage,
* This is made possible by the ``ApplyRule("toscrape.com", use=ProductPage,
to_return=Product)`` instance created from the ``@handle_urls`` decorator
on ``ProductPage``.

Expand All @@ -248,7 +248,7 @@ From this example, we can see that:

.. code-block:: python

@handle_urls("example.com")
@handle_urls("toscrape.com")
@attrs.define
class ProductPage(WebPage[Product]):
product_image_page: ProductImagePage
Expand All @@ -267,7 +267,7 @@ From this example, we can see that:

def start_requests(self):
yield scrapy.Request(
"https://example.com/products/some-product", self.parse
"https://toscrape.com/products/some-product", self.parse
)

async def parse(self, response: DummyResponse, product_page: ProductPage):
Expand Down