🥙 donerkebab 🥙
> A super easy to use, beginner friendly [selenium](https://pypi.org/project/selenium/) wrapper$ pip install donerkebab
Usage
1. Download the driver for your browser
2. Place it in a PATH directory
This might be /usr/bin or the directory as your python script
# Also available for Firefox, Edge, Safari and Opera
from donerkebab import ChromeDriver
# Get an instance of the browser window
# You can easily start it in headless mode too
driver = ChromeDriver(headless=False)
driver.open('https://duckduckgo.com/')
# Browser will wait at max 10 seconds until element is found
driver.set_timeout(10)
# You can find elements by their CSS selectors
input_box = driver.get_element('input#search_form_input_homepage')
# Uses classic selenium element functions
input_box.send_keys('Do pigs fly?')
driver.sleep(2)
submit_button = driver.get_element('input#search_button_homepage')
# Perform the search
submit_button.click()
# Get the container of all the result links
results_container = driver.get_element('div.results--main')
# Get all the links inside the container with a class of 'results__a'
results = driver.get_elements_in_parent(results_container, 'a.result__a')
# Print all the links
print("🔎 Results for 'Do pigs fly?' 🔎")
for result in results:
# get title and href attribute (the link adress) for every result
print(result.text + ' -> ' + result.get_attribute('href'))
driver.quit()
API
Driver init options
driver = FirefoxDriver(log=True, executable_path=None,headless=False, page_load_strategy='normal'):
headless -> Hides the window and runs the browser in the background. Really usefull
log -> Enable or disable logging
executable_path -> The full path to executable driver. If left null the it will look at the PATH variable to find the driver.
page_load_strategy -> Take a look at the [official docs](https://www.selenium.dev/documentation/webdriver/capabilities/shared/#pageloadstrategy)
Locating elements
Css selectors
donerkebab always uses css selectors for locating elements. Some examples:
inputelement with type inputdiv > inputelement that is the direct child of inputinput.searchelement with a class of 'search'input#main_buttonelement with an id of 'main_button'a[href='https://google.com']link element with a href attribute
Definately check out more advanced css selectors. They come in really handy
Locator methods
driver.get_element(css_selector)
driver.get_elements(css_selector)
driver.get_element_in_parent(parent_element, css_selector)
driver.get_elements_in_parent(parent_element, css_selector)
driver.get_element_by_xpath(xpath)
driver.is_element_present(css_selector) # Searches for element without any timeout
# Tries the first selector, if none element is found, tries the alternate selector
# Great for having backup selectors for elements that might change
driver.get_element_multiple_attempts(selector1, selector2, selector3...)
# Returns the active element
driver.active_element
# Scrolls that element into view
driver.scroll_to_element(element)
# Waits until an alert is present, and returns that alert
driver.get_alert()
Driver methods
open(url)
Opens the url and waits until the page loads. Url must start with https:// or http://
Release files for donerkebab 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| donerkebab-0.0.2.tar.gz | 7.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| donerkebab-0.0.2-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 16.6 kB
Release files / donerkebab-0.0.2.tar.gz
| Download URL | donerkebab-0.0.2.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b083d157719c773585a98de593553d5fcd05cf6b8041e31b6cdb614069f03361
|
|
BLAKE2b-256 checksum How to use checksums |
2136430e243260d8787509898f8f38edaab90b1d6ebd6e21e4f1a4ccf465bd53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
|
Release files / donerkebab-0.0.2-py2-none-any.whl
| Download URL | donerkebab-0.0.2-py2-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
f3a0574fa247f316d14fce1872debdf30f3361d6e61fd31a4567b62fa08dfbd5
|
|
BLAKE2b-256 checksum How to use checksums |
bcfc4d5622baf3e44e74da3b440ea0934eca5af65e8412d71ccdd38e63327146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
|