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

Add kwargs to parse to be compatible with base class #241

Merged
merged 1 commit into from
Nov 17, 2023
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
Add kwargs to parse to be compatible with base class
  • Loading branch information
SamuelMarks committed Nov 1, 2023
commit 985d775deedf1a521dd048880b829d28d61eefe1
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AwesomeSpider(scrapy.Spider):
meta={"playwright": True},
)

def parse(self, response):
def parse(self, response, **kwargs):
# 'response' contains the page as seen by the browser
return {"url": response.url}
```
Expand Down Expand Up @@ -430,7 +430,7 @@ def start_requests(self):
meta={"playwright": True, "playwright_include_page": True},
)

def parse(self, response):
def parse(self, response, **kwargs):
page = response.meta["playwright_page"]
yield scrapy.Request(
url="https://httpbin.org/headers",
Expand Down Expand Up @@ -467,7 +467,7 @@ about the give response. Only available for HTTPS requests. Could be accessed
in the callback via `response.meta['playwright_security_details']`

```python
def parse(self, response):
def parse(self, response, **kwargs):
print(response.meta["playwright_security_details"])
# {'issuer': 'DigiCert TLS RSA SHA256 2020 CA1', 'protocol': 'TLS 1.3', 'subjectName': 'www.example.org', 'validFrom': 1647216000, 'validTo': 1678838399}
```
Expand Down Expand Up @@ -609,7 +609,7 @@ you can access a context though the corresponding [`Page.context`](https://playw
attribute, and await [`close`](https://playwright.dev/python/docs/api/class-browsercontext#browser-context-close) on it.

```python
def parse(self, response):
def parse(self, response, **kwargs):
yield scrapy.Request(
url="https://example.org",
callback=self.parse_in_new_context,
Expand Down Expand Up @@ -672,7 +672,7 @@ class ProxySpider(Spider):
def start_requests(self):
yield Request("http://httpbin.org/get", meta={"playwright": True})

def parse(self, response):
def parse(self, response, **kwargs):
print(response.text)
```

Expand Down Expand Up @@ -741,7 +741,7 @@ def start_requests(self):
},
)

def parse(self, response):
def parse(self, response, **kwargs):
screenshot = response.meta["playwright_page_methods"][0]
# screenshot.result contains the image's bytes
```
Expand All @@ -754,7 +754,7 @@ def start_requests(self):
meta={"playwright": True, "playwright_include_page": True},
)

async def parse(self, response):
async def parse(self, response, **kwargs):
page = response.meta["playwright_page"]
screenshot = await page.screenshot(path="example.png", full_page=True)
# screenshot contains the image's bytes
Expand Down Expand Up @@ -846,7 +846,7 @@ class ClickAndSavePdfSpider(scrapy.Spider):
),
)

def parse(self, response):
def parse(self, response, **kwargs):
pdf_bytes = response.meta["playwright_page_methods"]["pdf"].result
with open("iana.pdf", "wb") as fp:
fp.write(pdf_bytes)
Expand All @@ -873,7 +873,7 @@ class ScrollSpider(scrapy.Spider):
),
)

async def parse(self, response):
async def parse(self, response, **kwargs):
page = response.meta["playwright_page"]
await page.screenshot(path="quotes.png", full_page=True)
await page.close()
Expand Down
2 changes: 1 addition & 1 deletion examples/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def start_requests(self):
dont_filter=True,
)

async def parse(self, response):
async def parse(self, response, **kwargs):
page = response.meta["playwright_page"]
context_name = response.meta["playwright_context"]
storage_state = await page.context.storage_state()
Expand Down
2 changes: 1 addition & 1 deletion examples/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def start_requests(self):
meta={"playwright": True},
)

def parse(self, response):
def parse(self, response, **kwargs):
if filename := response.meta.get("playwright_suggested_filename"):
(Path(__file__).parent / filename).write_bytes(response.body)
yield {
Expand Down
2 changes: 1 addition & 1 deletion examples/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ async def handle_dialog(self, dialog: Dialog) -> None:
async def handle_response(self, response: PlaywrightResponse) -> None:
self.logger.info(f"Received response with URL {response.url}")

def parse(self, response):
def parse(self, response, **kwargs):
return {"url": response.url}
2 changes: 1 addition & 1 deletion examples/exception_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ def start_requests(self):
meta={"playwright": True},
)

def parse(self, response):
def parse(self, response, **kwargs):
logging.info("Received response for %s", response.url)
yield {"url": response.url}
2 changes: 1 addition & 1 deletion examples/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ def start_requests(self):
cookies={"foo": "bar"},
)

def parse(self, response):
def parse(self, response, **kwargs):
headers = json.loads(response.css("pre::text").get())["headers"]
yield {"url": response.url, "headers": headers}
2 changes: 1 addition & 1 deletion examples/init_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def start_requests(self):
},
)

def parse(self, response):
def parse(self, response, **kwargs):
json_str = response.css("pre::text").get()
print(json_str)
return {"data": json.loads(json_str)}
2 changes: 1 addition & 1 deletion examples/max_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def start_requests(self):
meta={"playwright": True, "playwright_context": "b"},
)

def parse(self, response):
def parse(self, response, **kwargs):
return {"url": response.url}

async def errback(self, failure):
Expand Down
2 changes: 1 addition & 1 deletion examples/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ def start_requests(self):
},
)

def parse(self, response):
def parse(self, response, **kwargs):
yield {"url": response.url}
2 changes: 1 addition & 1 deletion examples/scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def start_requests(self):
},
)

def parse(self, response):
def parse(self, response, **kwargs):
return {"url": response.url, "count": len(response.css("div.quote"))}
2 changes: 1 addition & 1 deletion examples/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def start_requests(self):
},
)

async def parse(self, response):
async def parse(self, response, **kwargs):
page = response.meta["playwright_page"]
storage_state = await page.context.storage_state()
await page.close()
Expand Down
Loading