Created
February 7, 2024 04:31
-
-
Save fsndzomga/90bcc67831d4a9a67f54df8f34b1b885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.chrome.service import Service | |
from webdriver_manager.chrome import ChromeDriverManager | |
import time | |
def count_happy_scribe_selenium(url): | |
# Set up Chrome options | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_argument("--headless") # Run Chrome in headless mode | |
chrome_options.add_argument("--disable-gpu") | |
chrome_options.add_argument("--no-sandbox") | |
# Initialize the Chrome driver | |
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), | |
options=chrome_options) | |
# Go to the specified URL | |
driver.get(url) | |
# Wait for 20 seconds to load the page fully | |
time.sleep(20) | |
# After waiting, count occurrences of "Happy Scribe" | |
page_source = driver.page_source | |
count = page_source.count("Happy Scribe") | |
print(f"Happy Scribe appears {count} times.") | |
# Clean up | |
driver.quit() | |
# Call the function with the URL | |
count_happy_scribe_selenium("https://www.happyscribe.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment