A selenium wrapper with easy use, configuration and shorter code.
Project description
Details
Author: Edan
Version: 1.0.8.2
A selenium wrapper with easy use, configuration and shorter code.
Documentation
Steps
1. Installation
pip install chrometomato
2. Import
from chrometomato import Chrome
Initilization
chrome_arguments.yaml
this file is to set the browser user agent and launch arguments
user_agent: >-
user agent string
options:
- --mute-audio
cookies.txt
paste your cookies here
example.py
Initiate the chrome driver with your custom user agent, launch options and load cookies for a specific domain based on the yaml and txt files
from chrometomato import Chrome
chrome = Chrome('chrome_arguments.yaml', 'cookies.txt', 'example.com')
Functions
1. get
Navigate to a specific url
Parameters
Navigate to a url
url : str
The url to navigate to
chrome.get('example.com')
2. find_element
Find a web element by a specific selection method
Parameters
sm: sm
Selection method (sm.CLASS, sm.ID, sm.NAME, sm.CSS_SELECTOR, sm.XPATH)
value: str
A value of an id / class / name / css selector / xpath
timeout: int
Timeout to wait for the element to be found until an error is being thrown if the element is not found
from chrometomato import sm
element = chrome.find_element(sm.ID, 'element-id')
3. find_elements
Find an array of web elements by a specific selection method
Parameters
sm: sm
Selection method
value: str
The value to search for
timeout: int
Timeout in seconds (default: 10)
elements = chrome.find_elements(sm.CSS_SELECTOR, 'div.items')
4. element_exists
Determine if an element exists in the page or not
Parameters
sm: sm
Selection method
value: str
The value to search for
timeout: int
Timeout in seconds (default: 10)
if chrome.element_exists(sm.CLASS, 'my-class'):
print("Element exists!")
5. click_element
Find a web element and click it
Parameters
sm: sm
Selection method
value: str
The value to search for
timeout: int
Timeout in seconds (default: 10)
chrome.click_element(sm.XPATH, '//button[@id="submit"]')
6. scroll_element
Find a web element and scroll it until the end
Parameters
sm: sm
Selection method
value: str
The value to search for
timeout: int
Timeout in seconds (default: 10)
chrome.scroll_element(sm.ID, 'scrollable-container')
7. wait
Wait before executing a command
Parameters
seconds: float
Time in seconds to wait
chrome.wait(5.5)
8. title
Get the current title of the document
print(chrome.title)
9. page_source
Get the current page source (HTML)
print(chrome.page_source)
10. run
Loop your function until you forcefully exit or call quit
Parameters
process: function
Infinite loop function that you want to run
interval: int
Tickrate in seconds (default: 10)
def loop():
# your code here
chrome.run(loop, interval=5)
11. stays
Prevent chrome from closing (keeps the script running)
chrome.stays()
12. quit
Close the web browser and stop the running loop
chrome.quit()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file chrometomato-1.0.8.2.tar.gz.
File metadata
- Download URL: chrometomato-1.0.8.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c76776d835e5beac6ada5b0669686c3876286d8b8a112a74bb5a496cb6d6268f
|
|
| MD5 |
db89790bcfd91ee746dcd5072321e45b
|
|
| BLAKE2b-256 |
142eee35052d72afe0badf7adb05f62d625da160223374d42f5b1968c54119a9
|