Botasaurus Driver
Botasaurus Driver is a powerful Driver Automation Python library that offers the following benefits:
- It is really humane; it looks and works exactly like a real browser, allowing it to access any website.
- Compared to Selenium and Playwright, it is super fast to launch and use.
- The API is designed by and for web scrapers, and you will love it.
Installation
pip install botasaurus-driver
Bypassing Bot Detection: Code Example
from botasaurus_driver import Driver
driver = Driver()
driver.google_get("https://nopecha.com/demo/cloudflare", bypass_cloudflare=True)
driver.prompt()

API
Botasaurus Driver provides several handy methods for web automation tasks such as:
-
Visiting URLs:
driver.get("https://www.example.com")
driver.google_get("https://www.example.com")
driver.get_via("https://www.example.com", referer="https://duckduckgo.com/")
driver.get_via_this_page("https://www.example.com")
-
Finding elements:
from botasaurus.browser import Wait
search_results = driver.select(".search-results", wait=Wait.SHORT)
all_links = driver.select_all("a")
search_results = driver.wait_for_element(".search-results", wait=Wait.LONG)
hello_mom = driver.get_element_with_exact_text("Hello Mom", wait=Wait.VERY_LONG)
-
Interacting with elements:
driver.type("input[name='username']", "john_doe")
driver.click("button.submit")
element = driver.select("button.submit")
element.click()
element.select_option("select#fruits", index=2)
-
Retrieving element properties:
header_text = driver.get_text("h1")
error_message = driver.get_element_containing_text("Error: Invalid input")
image_url = driver.select("img.logo").get_attribute("src")
-
Working with parent-child elements:
parent_element = driver.select(".parent")
child_element = parent_element.select(".child")
child_element.click()
-
Executing JavaScript:
result = driver.run_js("script.js")
result = driver.run_js("return document.title")
pikachu = driver.run_js("return args.pokemon", {"pokemon": 'pikachu'})
text_content = driver.select("body").run_js("(el) => el.textContent")
-
Enable human mode to perform, human-like mouse movements and say sayonara to detection:
driver.get(
"https://nopecha.com/demo/cloudflare",
)
driver.long_random_sleep()
iframe = driver.get_element_at_point(160, 290)
checkbox = iframe.get_element_at_point(30, 30)
driver.enable_human_mode()
checkbox.click()
driver.disable_human_mode()
driver.prompt()

-
Drag and Drop:
driver.get("https://react-dnd.github.io/react-dnd/examples/tutorial")
draggable = driver.select('[draggable="true"]')
droppable = driver.select('[data-testid="(3,6)"]')
draggable.drag_and_drop_to(droppable)
driver.prompt()

-
Selecting Shadow Root Elements:
driver.get("https://nopecha.com/demo/cloudflare")
driver.long_random_sleep()
shadow_root_element = driver.select('[name="cf-turnstile-response"]').parent
iframe = shadow_root_element.get_shadow_root()
content = iframe.get_shadow_root()
print(content.select("label", wait = 8).text)
driver.prompt()

-
Monitoring requests:
from botasaurus.browser import browser, Driver, cdp
@browser()
def scrape_responses_task(driver: Driver, data):
def after_response_handler(
request_id: str,
response: cdp.network.Response,
event: cdp.network.ResponseReceived,
):
url = response.url
status = response.status
headers = response.headers
print(
"after_response_handler",
{
"request_id": request_id,
"url": url,
"status": status,
"headers": headers,
},
)
driver.responses.append(request_id)
driver.after_response_received(after_response_handler)
driver.get("https://example.com/")
collected_responses = driver.responses.collect()
return collected_responses
scrape_responses_task()
-
Working with iframes:
driver.get("https://www.freecodecamp.org/news/using-entity-framework-core-with-mongodb/")
iframe = driver.get_iframe_by_link("www.youtube.com/embed")
freecodecamp_youtube_subscribers_count = iframe.select(".ytp-title-expanded-subtitle").text
print(freecodecamp_youtube_subscribers_count)
-
Executing CDP Command:
from botasaurus.browser import browser, Driver, cdp
driver.run_cdp_command(cdp.page.navigate(url='https://stackoverflow.blog/open-source'))
-
Miscellaneous:
form.type("input[name='password']", "secret_password")
container.is_element_present(".button")
page_html = driver.page_html
driver.select(".footer").scroll_into_view()
driver.close()
Become one of our amazing stargazers by giving us a star ⭐ on GitHub!
It's just one click, but it means the world to me.
