A langchain tool implementation of Undetected with Selenium and Chrome for page fetching, making it easier to bypass bot detectors
Project description
Undetected Browser Tool
The goal of this tool is to make accessing individual web pages behind bot detection like cloudflare a little easier. It is not a hacking tool, it's not 100% guaranteed, there are different settings in firewall services that could still block this. For example this is still detectable through CDP (chrome developer protocol) javascript. It's purpose is to be able to access publicly accessible data a single page at a time. It's slow, as it creates a browser instance, and navigates to a page, so it's not a viable web crawler. But it makes fetching a webpage that might not be available to an AI agent easier.
This is a langchain tool based on Selenium and the undetected-chromedriver project.
Installation
pip install -U undetected-browser-tool
Usage
We use this in langchain agents or in CrewAI Agents
from undetected_browser_tool import UndetectedBrowserTool
# for a headless browser
browser = UndetectedBrowserTool(headless=True)
# or useful for debugging
browser = UndetectedBrowserTool(headless=False)
# or using a proxy, change http to https or socks5 to suit your proxy settings
opts = {"proxy-server" : "http://xxx.xxx.xxx:port"}
browser = UndetectedBrowserTool(headless=False, additional_opts=opts)
# fetch a page
page = browser.run("https://nowsecure.nl/")
Example with CrewAI
Untested code, written as an example for usage with CrewAI Be aware that langchain and Crew are in constant development, so these interfaces may change.
from crewai import Agent, Task, Crew
from undetected_browser_tool import UndetectedBrowserTool
from langchain_community.tools import DuckDuckGoSearchResults
browser = UndetectedBrowserTool(headless=True)
search_engine = DuckDuckGoSearchResults()
researcher = Agent(
role="Researcher",
goal="A document reviewing the top 5 solutions in {topic}",
backstory="You are a research analyst tasked with reviewing software for an IT firm to help them make buying decisions",
tools=[search_engine, browser],
)
report_writer = Agent(
role="Report writer",
goal="A executive review of the top 5 solutions in {topic}"
backstory="You are a report writer for an IT firm, you excel at writing summaries and detailed reports for executives in an IT firm",
)
research_task = Task(
expected_output="A list of pros and cons, features, customer reviews and pricing of the top 5 solutions in {topic}",
description="By using a search engine and Capterra, G2, Gartner write a review of the top 5 solutions in {topic}, include the source link for each item you find."
tools=[search_engine, browser],
agent=researcher,
)
report_task = Task(
expected_output="An executive style report, with a summary, detailed information and a recommendation for selecting a solution in {topic}"
description="Based upon the research provided, write an executive summary, detailed report, and a recommendation on the software selection. The report should have a table of features, pros / cons, and pricing options."
output_file="report.md",
context={research_task}
)
crew = Crew(agents=[researcher, report_writer], tasks=[research_task, report_task])
crew.kickoff(inputs={"topic" : "BI Reporting Platforms"})
Tips for being undetected
This is not a 100%, it's hard to be 100% but it's a good start.
- Don't go through a data center, those IPs are easy to track and block.
- Use proxies, and I recommend residential proxies. Tor networks are easily blocked.
- Switch proxies frequently
- Don't crawl the website, use a search service to try and pinpoint the page you need.
Every time a confirm you are a human page pops up, about 50% of the users just drop out, so companies who are dependent on traffic try to avoid that. Meaning as long as you're not doing something silly you're usually going to be ok.
Ethics
The use of automation tools to interact with websites is a nuanced topic that involves balancing access to information with respect for publishers' rights. Publishers have the right to protect their content and manage how it is accessed. They often allow search engines to index their data so it can be discovered by the general public, while also setting guidelines to regulate how their information is used.
If your intent is to occasionally access content to obtain information and properly reference the source, this tool can help streamline your workflow by automating repetitive tasks, thus saving time and effort.
However, if your goal is to scrape large amounts of data from a website, this project is not intended for that purpose. Engaging in large-scale scraping can violate the terms of service of many websites, infringe on intellectual property rights, and potentially cause harm to the website's infrastructure. For those needs, there are dedicated web scraping services and tools that are more appropriate and specifically designed to handle such activities.
Always ensure that your use of automation tools is ethical and complies with the website's terms of service. Respect the rights of content owners and use automation responsibly.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file undetected_browser_tool-0.3.tar.gz
.
File metadata
- Download URL: undetected_browser_tool-0.3.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 880529b9c959d76cde063dd1ef6e522df605dd577ff2aa54f0bb88189361fe09 |
|
MD5 | 7ca2b473f0d25484d6c6cad5b4884f3e |
|
BLAKE2b-256 | a4df72b07bd11621411f3a13c9f00a2ba280909ace8ef3ef16634e2aff62b87b |
File details
Details for the file undetected_browser_tool-0.3-py3-none-any.whl
.
File metadata
- Download URL: undetected_browser_tool-0.3-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 333d23517100486a4d5332a7d13c043b74b2f70d9cdc6dafa0bbc89e8d48fed1 |
|
MD5 | 141a0680317c71bf4e16f010f379ac5c |
|
BLAKE2b-256 | b7f38bed753ec02e3031354e7a4eaf7f68f73e12c763c5d5b25c12c13704ce5b |