Open h9052300 opened 4 days ago
Can you provide more details about the Usage?
Of course!
This project utilizes Selenium, a powerful browser automation framework that lets you control your browser through code. When browsers are controlled by scripts (often referred to as "puppet browsers"), they typically set specific properties that can be detected by services like Cloudflare. For instance, properties such as navigator.webdriver
can be checked using JavaScript, which may restrict access to content on sites protected by such services.
To address this issue, the Undetected Geckodriver acts as an interface between your code and Selenium. When you create a new WebDriver instance using the Firefox()
class from the undetected_geckodriver
package (as opposed to using Selenium directly), the following processes occur:
navigator.webdriver
, during Selenium operations.This approach allows you to utilize Selenium without being flagged as a bot by services like Cloudflare.
You can integrate Undetected GeckoDriver into your existing Selenium code by simply replacing the selenium.webdriver.Firefox
imports with undetected_geckodriver.Firefox
.
Here are a couple of examples demonstrating how you can use this project:
from undetected_geckodriver import Firefox
driver = Firefox()
driver.get("https://www.example.com")
import time
from undetected_geckodriver import Firefox
from selenium.webdriver.common.by import By
# Constants
SEARCH_FOR = "Undetected Geckodriver 1337!"
GOOGLE_URL = "https://www.google.com"
# Initialize the undetected Firefox browser
driver = Firefox()
# Navigate to Google
driver.get(GOOGLE_URL)
# Locate the search box and perform the search
search_box = driver.find_element(By.NAME, "q") # Find the search box in the DOM (Document Object Model)
search_box.send_keys(SEARCH_FOR) # Input the search term
search_box.submit() # Submit the search
# Wait for the page to load
time.sleep(2)
# Print the current URL after the search
print("Current URL:", driver.current_url)
# Wait for a while to observe the results
time.sleep(15)
# Ensure the browser is closed
driver.quit() # Close the browser
For further information and advanced usage, you can take a look at the official Selenium documentation.
If you have any additional questions, feel free to ask!
Can you provide more details about the Usage?