-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added `Compose` action in actions.py. Some formatting. * Fix closing context * Update for pyppeteer and playwright. * Doc and example * Typing issue * Fixed stand-alone `Compose`. * Changes? * Fixed example spider * Playwright and Pyppeteer fixes * Better example * Standard execution method * increment version + minor fix --------- Co-authored-by: Max Varlamov <[email protected]>
- Loading branch information
1 parent
a35eaa0
commit 98704eb
Showing
8 changed files
with
155 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from logging import ERROR | ||
|
||
import scrapy | ||
from scrapy.utils.log import failure_to_exc_info | ||
from twisted.python.failure import Failure | ||
|
||
from scrapypuppeteer import ( | ||
PuppeteerRequest, | ||
PuppeteerResponse, | ||
PuppeteerScreenshotResponse, | ||
) | ||
from scrapypuppeteer.actions import Click, Compose, GoTo, Screenshot, Scroll | ||
|
||
|
||
class ComposeSpider(scrapy.Spider): | ||
name = "compose" | ||
|
||
custom_settings = { | ||
"DOWNLOADER_MIDDLEWARES": { | ||
"scrapypuppeteer.middleware.PuppeteerServiceDownloaderMiddleware": 1042, | ||
}, | ||
} | ||
|
||
def start_requests(self): | ||
goto = GoTo("https://pptr.dev") | ||
click_1 = Click( | ||
"#__docusaurus > nav > div.navbar__inner > div:nth-child(1) > a:nth-child(3)" | ||
) | ||
click_2 = Click( | ||
"#__docusaurus_skipToContent_fallback > div > div > aside > div > " | ||
"div > nav > ul > li:nth-child(1) > ul > li:nth-child(3) > a" | ||
) | ||
click = Compose(click_1, click_2) | ||
scroll = Scroll() | ||
screenshot = Screenshot(options={"full_page": True, "type": "jpeg"}) | ||
|
||
compose_action = Compose( | ||
goto, | ||
click, | ||
scroll, | ||
screenshot, | ||
) | ||
|
||
yield PuppeteerRequest( | ||
compose_action, | ||
callback=self.parse, | ||
errback=self.errback, | ||
close_page=True, | ||
) | ||
|
||
def parse(self, response: PuppeteerResponse): | ||
assert isinstance(response, PuppeteerScreenshotResponse) | ||
self.log("Spider worked fine!") | ||
|
||
def errback(self, failure: Failure): | ||
print(failure) | ||
self.log(failure_to_exc_info(failure), level=ERROR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters