@@ -326,54 +326,75 @@ async def parse_in_new_context(self, response):
326326```
327327
328328
329- # # Page coroutines
329+ # # Executing actions on pages
330330
331331A sorted iterable (`list ` , `tuple ` or `dict ` , for instance) could be passed
332- in the `playwright_page_coroutines `
332+ in the `playwright_page_methods `
333333[Request.meta](https:// docs.scrapy.org/ en/ latest/ topics/ request- response.html# scrapy.http.Request.meta)
334334key to request coroutines to be awaited on the `Page` before returning the final
335335`Response` to the callback.
336336
337337This is useful when you need to perform certain actions on a page, like scrolling
338- down or clicking links, and you want everything to count as a single Scrapy
339- Response, containing the final result.
338+ down or clicking links, and you want to handle only the final result in your callback.
340339
341- # ## `PageCoroutine ` class
340+ # ## `PageMethod ` class
342341
343- * `scrapy_playwright.page.PageCoroutine (method: str , * args, ** kwargs)` :
342+ # ### `scrapy_playwright.page.PageMethod (method: str, *args, **kwargs)`:
344343
345- Represents a coroutine to be awaited on a `playwright.page.Page` object ,
346- such as " click" , " screenshot" , " evaluate" , etc.
347- `method` should be the name of the coroutine , `* args` and `** kwargs`
348- are passed to the function call . The return value of the coroutine call
349- will be stored in the `PageCoroutine .result` attribute.
344+ Represents a method to be called ( and awaited if necessary) on a
345+ `playwright.page.Page` object , such as " click" , " screenshot" , " evaluate" , etc.
346+ `method` is the name of the method , `* args` and `** kwargs`
347+ are passed when calling such method . The return value
348+ will be stored in the `PageMethod .result` attribute.
350349
351- For instance,
352- ```python
353- PageCoroutine(" screenshot" , path = " quotes.png" , fullPage = True )
354- ```
350+ For instance,
351+ ```python
352+ def start_requests(self ):
353+ yield Request(
354+ url = " https://example.org" ,
355+ meta = {
356+ " playwright" : True ,
357+ " playwright_page_methods" : [
358+ PageMethod(" screenshot" , path = " example.png" , fullPage = True ),
359+ ],
360+ },
361+ )
355362
356- produces the same effect as :
357- ```python
358- # 'page' is a playwright.async_api.Page object
359- await page.screenshot(path = " quotes.png" , fullPage = True )
360- ```
363+ def parse(self , response):
364+ screenshot = response.meta[" playwright_page_methods" ][0 ]
365+ # screenshot.result contains the image's bytes
366+ ```
361367
368+ produces the same effect as :
369+ ```python
370+ def start_requests(self ):
371+ yield Request(
372+ url = " https://example.org" ,
373+ meta = {" playwright" : True , " playwright_include_page" : True },
374+ )
362375
363- # ## Supported coroutines
376+ async def parse(self , response):
377+ page = response.meta[" playwright_page" ]
378+ await page.screenshot(path = " example.png" , full_page = True )
379+ await page.close()
380+ ```
381+
382+
383+ # ## Supported methods
364384
365385Please refer to the [upstream docs for the `Page` class ](https:// playwright.dev/ python/ docs/ api/ class - page)
366- to see available coroutines
386+ to see available methods.
367387
368388# ## Impact on Response objects
369389
370390Certain `Response` attributes (e.g. `url` , `ip_address` ) reflect the state after the last
371- action performed on a page. If you issue a `PageCoroutine ` with an action that results in
391+ action performed on a page. If you issue a `PageMethod ` with an action that results in
372392a navigation (e.g. a `click` on a link), the `Response.url` attribute will point to the
373393new URL , which might be different from the request' s URL.
374394
375395
376396# # Page events
397+
377398A dictionary of Page event handlers can be specified in the `playwright_page_event_handlers`
378399[Request.meta](https:// docs.scrapy.org/ en/ latest/ topics/ request- response.html# scrapy.http.Request.meta) key.
379400Keys are the name of the event to be handled (`dialog` , `download` , etc).
@@ -430,15 +451,15 @@ class ClickAndSavePdfSpider(scrapy.Spider):
430451 url = " https://example.org" ,
431452 meta = dict (
432453 playwright = True ,
433- playwright_page_coroutines = {
434- " click" : PageCoroutine (" click" , selector = " a" ),
435- " pdf" : PageCoroutine (" pdf" , path = " /tmp/file.pdf" ),
454+ playwright_page_methods = {
455+ " click" : PageMethod (" click" , selector = " a" ),
456+ " pdf" : PageMethod (" pdf" , path = " /tmp/file.pdf" ),
436457 },
437458 ),
438459 )
439460
440461 def parse(self , response):
441- pdf_bytes = response.meta[" playwright_page_coroutines " ][" pdf" ].result
462+ pdf_bytes = response.meta[" playwright_page_methods " ][" pdf" ].result
442463 with open (" iana.pdf" , " wb" ) as fp:
443464 fp.write(pdf_bytes)
444465 yield {" url" : response.url} # response.url is "https://www.iana.org/domains/reserved"
@@ -456,10 +477,10 @@ class ScrollSpider(scrapy.Spider):
456477 meta = dict (
457478 playwright = True ,
458479 playwright_include_page = True ,
459- playwright_page_coroutines = [
460- PageCoroutine (" wait_for_selector" , " div.quote" ),
461- PageCoroutine (" evaluate" , " window.scrollBy(0, document.body.scrollHeight)" ),
462- PageCoroutine (" wait_for_selector" , " div.quote:nth-child(11)" ), # 10 per page
480+ playwright_page_methods = [
481+ PageMethod (" wait_for_selector" , " div.quote" ),
482+ PageMethod (" evaluate" , " window.scrollBy(0, document.body.scrollHeight)" ),
483+ PageMethod (" wait_for_selector" , " div.quote:nth-child(11)" ), # 10 per page
463484 ],
464485 ),
465486 )
@@ -487,7 +508,14 @@ For more examples, please see the scripts in the [examples](examples) directory.
487508 Refer to the [Proxy support](# proxy-support) section for more information.
488509
489510
490- # # Deprecations
511+ # # Deprecation policy
512+
513+ Deprecated features will be supported for at least six months
514+ following the release that deprecated them. After that, they
515+ may be removed at any time. See the [changelog](changelog.md)
516+ for more information about deprecations and removals.
517+
518+ # ## Currently deprecated features
491519
492520* `PLAYWRIGHT_CONTEXT_ARGS ` setting (type `dict ` , default `{}` )
493521
@@ -497,3 +525,15 @@ For more examples, please see the scripts in the [examples](examples) directory.
497525 Deprecated since
498526 [`v0.0.4` ](https:// github.com/ scrapy- plugins/ scrapy- playwright/ releases/ tag/ v0.0.4),
499527 use the `PLAYWRIGHT_CONTEXTS ` setting instead
528+
529+ * `scrapy_playwright.page.PageCoroutine` class
530+
531+ Deprecated since
532+ [`v0.0.14` ](https:// github.com/ scrapy- plugins/ scrapy- playwright/ releases/ tag/ v0.0.14),
533+ use `scrapy_playwright.page.PageMethod` instead
534+
535+ * `playwright_page_coroutines` Request meta key
536+
537+ Deprecated since
538+ [`v0.0.14` ](https:// github.com/ scrapy- plugins/ scrapy- playwright/ releases/ tag/ v0.0.14),
539+ use `playwright_page_methods` instead
0 commit comments