-
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.
* # * add-FormAction * add documentation * Update local_browser_manager.py * add examples * code formatting * FormAction to FillForm * Formatting and Unused imports * form_action to fill_form * Extra parameter --------- Co-authored-by: matthew <[email protected]>
- Loading branch information
1 parent
f0f9641
commit 74b59a8
Showing
13 changed files
with
301 additions
and
123 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 |
---|---|---|
|
@@ -10,3 +10,5 @@ | |
} | ||
|
||
PUPPETEER_SERVICE_URL = "http://localhost:3000" | ||
|
||
PUPPETEER_LOCAL = False |
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,38 @@ | ||
import scrapy | ||
from scrapypuppeteer import PuppeteerRequest, PuppeteerScreenshotResponse | ||
from scrapypuppeteer.actions import Screenshot, FillForm | ||
import base64 | ||
|
||
|
||
class FormActionSpider(scrapy.Spider): | ||
name = "fill_form" | ||
start_urls = ["https://www.roboform.com/filling-test-all-fields"] | ||
|
||
def start_requests(self): | ||
for url in self.start_urls: | ||
yield PuppeteerRequest(url, callback=self.form_action, close_page=False) | ||
|
||
def form_action(self, response): | ||
input_mapping = { | ||
'input[name="02frstname"]': {"value": "SomeName", "delay": 50}, | ||
'input[name="05_company"]': {"value": "SomeCompany", "delay": 100}, | ||
'input[name="06position"]': {"value": "SomePosition", "delay": 100}, | ||
} | ||
|
||
yield response.follow( | ||
FillForm(input_mapping), close_page=False, callback=self.screenshot | ||
) | ||
|
||
def screenshot(self, response): | ||
action = Screenshot( | ||
options={ | ||
"fullPage": True, | ||
} | ||
) | ||
yield response.follow(action, callback=self.make_screenshot, close_page=False) | ||
|
||
@staticmethod | ||
def make_screenshot(response: PuppeteerScreenshotResponse, **kwargs): | ||
data = response.screenshot | ||
with open(f"screenshot.png", "wb") as fh: | ||
fh.write(base64.b64decode(data)) |
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,29 @@ | ||
import scrapy | ||
from scrapypuppeteer import PuppeteerRequest | ||
from scrapypuppeteer.actions import Har | ||
|
||
|
||
def write_to_file(file_path, content): | ||
with open(file_path, "a", encoding="utf-8") as file: | ||
file.write(content) | ||
|
||
|
||
class HarSpider(scrapy.Spider): | ||
name = "har" | ||
start_urls = ["https://github.com/pyppeteer/pyppeteer"] | ||
|
||
def start_requests(self): | ||
for url in self.start_urls: | ||
yield PuppeteerRequest( | ||
url, callback=self.har, close_page=False, har_recording=True | ||
) | ||
|
||
def har(self, response): | ||
yield response.follow( | ||
Har(), | ||
close_page=False, | ||
callback=self.save_har, | ||
) | ||
|
||
def save_har(self, response): | ||
write_to_file("result.har", response.har) |
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
Oops, something went wrong.