python -m pip install bota botasaurus botasaurus-api botasaurus-requests botasaurus-driver bota botasaurus-proxy-authentication botasaurus-server --upgrade
.How wonderful that of all the web scraping tools out there, you chose to learn about Botasaurus. Congratulations!
And now that you are here, you are in for an exciting, unusual and rewarding journey that will make your web scraping life a lot, lot easier.
Now, let me tell you in bullet points about Botasaurus. (Because as per the marketing gurus, YOU as a member of Developer Tribe have a VERY short attention span.)
So, what is Botasaurus?
Botasaurus is an all-in-one web scraping framework that enables you to build awesome scrapers in less time, less code, and with more fun.
A Web Scraping Magician has put all his web scraping experience and best practices into Botasaurus to save you hundreds of hours of Development Time!
Now, for the magical powers awaiting you after learning Botasaurus:
Save up to 97%, yes 97% on browser proxy costs by using browser-based fetch requests.
Easily save hours of Development Time with easy parallelization, profiles, extensions, and proxy configuration. Botasaurus makes asynchronous, parallel scraping a child's play.
Use Caching, Sitemap, Data cleaning, and other utilities to save hours of time spent in writing and debugging code.
Easily scale your scraper to multiple machines with Kubernetes, and get your data faster than ever.
And those are just the highlights. I Mean!
There is so much more to Botasaurus, that you will be amazed at how much time you will save with it.
Let's dive right in with a straightforward example to understand Botasaurus.
In this example, we will go through the steps to scrape the heading text from https://www.omkar.cloud/.
First things first, you need to install Botasaurus. Run the following command in your terminal:
python -m pip install botasaurus
Next, let's set up the project:
mkdir my-botasaurus-project cd my-botasaurus-project code . # This will open the project in VSCode if you have it installed
Now, create a Python script named main.py
in your project directory and paste the following code:
from botasaurus.browser import browser, Driver @browser def scrape_heading_task(driver: Driver, data): # Visit the Omkar Cloud website driver.get("https://www.omkar.cloud/") # Retrieve the heading element's text heading = driver.get_text("h1") # Save the data as a JSON file in output/scrape_heading_task.json return { "heading": heading } # Initiate the web scraping task scrape_heading_task()
Let's understand this code:
scrape_heading_task
, decorated with @browser
:@browser def scrape_heading_task(driver: Driver, data):
def scrape_heading_task(driver: Driver, data):
scrape_heading_task.json
by Botasaurus:driver.get("https://www.omkar.cloud/") heading = driver.get_text("h1") return {"heading": heading}
# Initiate the web scraping task scrape_heading_task()
Time to run it:
python main.py
After executing the script, it will:
output/scrape_heading_task.json
.Now, let's explore another way to scrape the heading using the request
module. Replace the previous code in main.py
with the following:
from botasaurus.request import request, Request from botasaurus.soupify import soupify @request def scrape_heading_task(request: Request, data): # Visit the Omkar Cloud website response = request.get("https://www.omkar.cloud/") # Create a BeautifulSoup object soup = soupify(response) # Retrieve the heading element's text heading = soup.find('h1').get_text() # Save the data as a JSON file in output/scrape_heading_task.json return { "heading": heading } # Initiate the web scraping task scrape_heading_task()
In this code:
request
, which is specifically designed for making browser-like humane requests.BeautifulSoup
object using soupify()
and extract the heading.Finally, run it again:
python main.py
This time, you will observe the exact same result as before, but instead of opening a whole Browser, we are making browser-like humane HTTP requests.
Botasaurus Driver is a web automation driver like Selenium, and the single most important reason to use it is because it is truly humane, and you will not, and I repeat NOT, have any issues with accessing any website.
Plus, it is super fast to launch and use, and the API is designed by and for web scrapers, and you will love it.
Cloudflare is the most popular protection system on the web. So, let's see how Botasaurus can help you solve various Cloudflare challenges.
Connection Challenge
This is the single most popular challenge and requires making a browser-like connection with appropriate headers. It's commonly used for:
Example Page: https://www.g2.com/products/github/reviews
from botasaurus.browser import browser, Driver @browser def scrape_heading_task(driver: Driver, data): # Visit the website via Google Referrer driver.google_get("https://www.g2.com/products/github/reviews") driver.prompt() heading = driver.get_text('.product-head__title [itemprop="name"]') return heading scrape_heading_task()
from botasaurus.request import request, Request @request(max_retry=10) def scrape_heading_task(request: Request, data): response = request.get('https://www.g2.com/products/github/reviews') print(response.status_code) response.raise_for_status() return response.text scrape_heading_task()
JS with Captcha Challenge
This challenge requires performing JS computations that differentiate a Chrome controlled by Selenium/Puppeteer/Playwright from a real Chrome. It also involves solving a Captcha. It's used to for pages which are rarely but sometimes visited by people, like:
Example Page: https://www.g2.com/products/github/reviews.html?page=5&product_id=github
Using @request
does not work because although it can make browser-like HTTP requests, it cannot run JavaScript to solve the challenge.
Pass the bypass_cloudflare=True
argument to the google_get
method.
from botasaurus.browser import browser, Driver @browser def scrape_heading_task(driver: Driver, data): driver.google_get("https://www.g2.com/products/github/reviews.html?page=5&product_id=github", bypass_cloudflare=True) driver.prompt() heading = driver.get_text('.product-head__title [itemprop="name"]') return heading scrape_heading_task()
Here are some benefits of creating a scraper with a user interface:
Let's run the Botasaurus Starter Template (the recommended template for greenfield Botasaurus projects), which scrapes the heading of the provided link by following these steps:
Clone the Starter Template:
git clone https://github.com/omkarcloud/botasaurus-starter my-botasaurus-project
cd my-botasaurus-project
Install dependencies (will take a few minutes):
python -m pip install -r requirements.txt
python run.py install
Run the scraper:
python run.py
Your browser will automatically open up at http://localhost:3000/. Then, enter the link you want to scrape (e.g., https://www.omkar.cloud/) and click on the Run Button.
After some seconds, the data will be scraped.
Visit http://localhost:3000/output to see all the tasks you have started.
Go to http://localhost:3000/about to see the rendered README.md file of the project.
Finally, visit http://localhost:3000/api-integration to see how to access the Scraper via API.
The API Documentation is generated dynamically based on your Scraper's Inputs, Sorts, Filters, etc., and is unique to your Scraper.
So, whenever you need to run the Scraper via API, visit this tab and copy the code specific to your Scraper.
Creating a UI Scraper with Botasaurus is a simple 3-step process:
To understand these steps, let's go through the code of the Botasaurus Starter Template that you just ran.
In src/scrape_heading_task.py
, we define a scraping function which basically does the following:
data
object and extracts the "link".from botasaurus.request import request, Request from botasaurus.soupify import soupify @request def scrape_heading_task(request: Request, data): # Visit the Link response = request.get(data["link"]) # Create a BeautifulSoup object soup = soupify(response) # Retrieve the heading element's text heading = soup.find('h1').get_text() # Save the data as a JSON file in output/scrape_heading_task.json return { "heading": heading }
In backend/scrapers.py
, we:
Server.add_scraper()
to register the scraperfrom botasaurus_server.server import Server from src.scrape_heading_task import scrape_heading_task # Add the scraper to the server Server.add_scraper(scrape_heading_task)
In backend/inputs/scrape_heading_task.js
we:
getInput
function that takes the controls parameter/** * @typedef {import('../../frontend/node_modules/botasaurus-controls/dist/index').Controls} Controls */ /** * @param {Controls} controls */ function getInput(controls) { controls // Render a Link Input, which is required, defaults to "https://www.omkar.cloud/". .link('link', { isRequired: true, defaultValue: "https://www.omkar.cloud/" }) }
Above was a simple example; below is a real-world example with multi-text, number, switch, select, section, and other controls.
/** * @typedef {import('../../frontend/node_modules/botasaurus-controls/dist/index').Controls} Controls */ /** * @param {Controls} controls */ function getInput(controls) { controls .listOfTexts('queries', { defaultValue: ["Web Developers in Bangalore"], placeholder: "Web Developers in Bangalore", label: 'Search Queries', isRequired: true }) .section("Email and Social Links Extraction", (section) => { section.text('api_key', { placeholder: "2e5d346ap4db8mce4fj7fc112s9h26s61e1192b6a526af51n9", label: 'Email and Social Links Extraction API Key', helpText: 'Enter your API key to extract email addresses and social media links.', }) }) .section("Reviews Extraction", (section) => { section .switch('enable_reviews_extraction', { label: "Enable Reviews Extraction" }) .numberGreaterThanOrEqualToZero('max_reviews', { label: 'Max Reviews per Place (Leave empty to extract all reviews)', placeholder: 20, isShown: (data) => data['enable_reviews_extraction'], defaultValue: 20, }) .choose('reviews_sort', { label: "Sort Reviews By", isRequired: true, isShown: (data) => data['enable_reviews_extraction'], defaultValue: 'newest', options: [{ value: 'newest', label: 'Newest' }, { value: 'most_relevant', label: 'Most Relevant' }, { value: 'highest_rating', label: 'Highest Rating' }, { value: 'lowest_rating', label: 'Lowest Rating' }] }) }) .section("Language and Max Results", (section) => { section .addLangSelect() .numberGreaterThanOrEqualToOne('max_results', { placeholder: 100, label: 'Max Results per Search Query (Leave empty to extract all places)' }) }) .section("Geo Location", (section) => { section .text('coordinates', { placeholder:
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
字节跳动发布的AI编程神器IDE
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。
专业的AI公文写作平台,公文写作神器
AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。
openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。
高分辨率纹理 3D 资产生成
Hunyuan3D-2 是腾讯开发的用于 3D 资产生成的强大工具,支持从文 本描述、单张图片或多视角图片生成 3D 模型,具备快速形状生成能力,可生成带纹理的高质量 3D 模型,适用于多个领域,为 3D 创作提供了高效解决方案。
一个具备存储、管理和客户端操作等多种功能的分布式文件系统相关项目。
3FS 是一个功能强大的分布式文件系统项目,涵盖了存储引擎、元数据管理、客户端工具等多个模块。它支持多种文件操作,如创建文件和目录、设置布局等,同时具备高效的事件循环、节点选择和协程池管理等特性。适用于需要大规模数据存储和管理的场景,能够提高系统的性能和可靠性,是分布式存储领域的优质解决方案。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号