Skip to content

feat: support for undetected_chromedriver with selenium backend #729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/groq/smart_scraper_groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"api_key": groq_key,
"temperature": 0
},
"headless": False
"headless": False,
"backend": "undetected_chromedriver"
}

# ************************************************
Expand Down
24 changes: 23 additions & 1 deletion scrapegraphai/docloaders/chromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ def __init__(
self.urls = urls
self.load_state = load_state

async def ascrape_undetected_chromedriver(self, url: str) -> str:
"""
Asynchronously scrape the content of a given URL using undetected chrome with Selenium.

Args:
url (str): The URL to scrape.

Returns:
str: The scraped HTML content or an error message if an exception occurs.

"""
import undetected_chromedriver as uc

logger.info(f"Starting scraping with {self.backend}...")
results = ""
try:
driver = uc.Chrome(headless=self.headless)
results = driver.get(url).page_content
except Exception as e:
results = f"Error: {e}"
return results

async def ascrape_playwright(self, url: str) -> str:
"""
Asynchronously scrape the content of a given URL using Playwright's async API.
Expand All @@ -75,7 +97,7 @@ async def ascrape_playwright(self, url: str) -> str:
from playwright.async_api import async_playwright
from undetected_playwright import Malenia

logger.info("Starting scraping...")
logger.info(f"Starting scraping with {self.backend}...")
results = ""
async with async_playwright() as p:
browser = await p.chromium.launch(
Expand Down