Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKorzh committed Aug 12, 2024
1 parent da3b321 commit 0aaee42
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Here is the list of available actions:
- `Scroll(selector, wait_options)` - scroll page
- `Screenshot(options)` - take screenshot
- `Har()` - to get the HAR file, pass the `har_recording=True` argument to `PuppeteerRequest` at the start of execution.
- `FormAction(input_mapping, submit_button)` - to fill out and submit forms on page.
- `RecaptchaSolver(solve_recaptcha)` - find or solve recaptcha on page
- `CustomJsAction(js_function)` - evaluate JS function on page

Expand Down Expand Up @@ -174,4 +175,4 @@ In this case RecaptchaMiddleware will just skip the request.
- [ ] headers and cookies management
- [ ] proxy support for puppeteer
- [x] error handling for requests
- [ ] har support
- [x] har support
31 changes: 30 additions & 1 deletion scrapypuppeteer/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,42 @@ def payload(self):


class Har(PuppeteerServiceAction):

"""
The `Har` action is used to capture and retrieve the HTTP Archive (HAR) file,
which contains detailed information about network requests and responses
made during the session.
This action is called without any arguments. To generate the HAR file,
you must pass the `har_recording=True` argument to `PuppeteerRequest`
when initiating the request.
"""
endpoint = "har"

def payload(self):
return {}


class FormAction(PuppeteerServiceAction):

"""
Fill out and submit forms on a webpage.
Available options:
* ``input_mapping`` (dict): A dictionary where each key is a CSS selector, and
each value is another dictionary containing details about the input for that element.
Each entry in the dictionary should follow this structure:
* ``selector`` (str): The CSS selector for the input element (used as the key).
* ``value`` (str): The text to be inputted into the element.
* ``delay`` (int, optional): A delay (in milliseconds) between each keystroke
when inputting the text. Defaults to 0 if not provided.
* ``submit_button`` (str, optional): The CSS selector for the form's submit button.
If provided, the button will be clicked after filling in the form.
"""

endpoint = "form_action"

def __init__(self, input_mapping: dict, submit_button: str = None):
Expand All @@ -241,7 +270,7 @@ def __init__(self, input_mapping: dict, submit_button: str = None):

def payload(self):
return {"inputMapping": self.input_mapping, "submitButton": self.submit_button}




Expand Down
1 change: 1 addition & 0 deletions scrapypuppeteer/browser_managers/local_browser_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,4 @@ def recaptcha_solver(self, request: PuppeteerRequest):

def har(self, request: PuppeteerRequest):
raise ValueError("Har is not available in local mode")

0 comments on commit 0aaee42

Please sign in to comment.