-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathpost.py
34 lines (28 loc) · 1.01 KB
/
post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from pathlib import Path
from scrapy import Spider, FormRequest
from scrapy_playwright.page import PageMethod
class PostSpider(Spider):
"""Send data using the POST verb."""
name = "post"
custom_settings = {
"TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor",
"DOWNLOAD_HANDLERS": {
"https": "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler",
# "http": "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler",
},
}
def start_requests(self):
yield FormRequest(
url="https://httpbin.org/post",
formdata={"foo": "bar"},
meta={
"playwright": True,
"playwright_page_methods": [
PageMethod(
"screenshot", path=Path(__file__).parent / "post.png", full_page=True
),
],
},
)
def parse(self, response, **kwargs):
yield {"url": response.url}