OctSum
00:00 / 10:57

Mervin Praison · 10:57

i asked my ai agent to read a price from a website.

我让我的 AI 代理从一个网站上读取价格。

my ai agent said the price was not on the page.

我的 AI 代理说页面上没有这个价格。

but the price was right there.

但价格明明就在那儿。

the problem was the scraping tool i used.

问题出在我使用的抓取工具上。

a scraping tool copies web pages so your ai can read them.

抓取工具会复制网页,这样你的 AI 就能读取它们。

my scraping tool removed the price and did not warn me.

我的抓取工具删掉了价格,却没有提醒我。

some web pages can also trick your ai by hiding secret instructions in the page.

有些网页还会通过在页面中隐藏秘密指令来欺骗你的 AI。

in my test, my ai was tricked three times out of three.

在我的测试中,我的 AI 三次都被骗了。

if your ai reads a page wrong, it gives you wrong answers.

如果你的 AI 错误地读取了页面,它就会给出错误答案。

so how do you know your ai read the page correctly?

那么,你怎么知道你的 AI 正确读取了页面呢?

today you'll learn ai web scraping step by step for free in under 10 minutes.

今天,你将在 10 分钟以内免费逐步学习 AI 网页抓取。

here's what you'll see step by step.

下面是你将逐步了解的内容。

crawling means visiting web pages and copying them the same as scraping.

爬取就是访问网页并复制它们,和抓取的意思一样。

first, how your ai agent sees a web page.

首先,了解你的 AI 代理如何查看网页。

step 1, basic crawling.

第 1 步,基础爬取。

copy any page so your ai can read it.

复制任意页面,让你的 AI 可以读取它。

step 2, check the facts are still there.

第 2 步,检查这些事实是否仍然存在。

step 3, javascript pages, how to crawl pages that come back empty.

第 3 步,JavaScript 页面:如何爬取那些返回空内容的页面。

step 4, hidden instructions, stop pages that trick your ai.

第 4 步,隐藏指令:阻止那些会欺骗你的 AI 的页面。

then, crawling at scale, thousands of pages a day.

然后,进行大规模爬取,每天处理数千个页面。

step 5, test it on 12 real websites.

第 5 步,在 12 个真实网站上测试。

step 6, agentic crawling, give the reader to your own ai agent and which tool to use.

第 6 步,智能体式抓取:把 Reader 交给你自己的 AI 智能体,并告诉它使用哪个工具。

truffletura, crawl4ai, gina reader, context.

Truffletura、Crawl4AI、Gina Reader、Context。

dev, or my safereader.

Dev,或者我的 SafeReader。

plus the one attack no filter can stop.

再加上一个任何过滤器都无法阻止的攻击。

that's exactly what we'll see today.

这正是我们今天要看的内容。

but first, how does your agent see a page?

但首先,你的智能体是怎样查看网页的?

before that, i regularly create videos about artificial intelligence on my youtube channel, so do subscribe and click the bell icon to stay tuned.

在继续之前,我经常在 YouTube 频道发布有关人工智能的视频,记得订阅并点击铃铛图标,以便及时收看。

and make sure you click the like button, so this video can be helpful for many others like you.

也别忘了点击赞,这样这段视频就能帮助更多和你一样的人。

an ai agent is a program that does jobs for you.

AI 智能体是一种替你完成任务的程序。

it opens links and acts on what it finds.

它会打开链接,并根据发现的内容采取行动。

ChatGPT, claude and gemini can all read a link you give them.

ChatGPT、Claude 和 Gemini 都能读取你提供给它们的链接。

many people also build their own agents.

很多人也会构建自己的智能体。

this is for you if your agent reads websites, like prices, news or research.

如果你的智能体会读取网站内容,比如价格、新闻或研究资料,那么这段内容就是为你准备的。

your agent can't look at a page like you do.

你的智能体无法像你一样查看网页。

it only gets the text that some code copied for it.

它只能获取某段代码为它复制的文本。

you see the finished page, your agent gets what's under it.

你看到的是完整的网页,你的智能体拿到的却是网页底层的内容。

the code, the hidden parts, or nothing at all.

可能是代码、隐藏内容,也可能什么都没有。

so your agent is only as good as the copy it gets.

所以,你的智能体能力如何,完全取决于它拿到的副本。

but what happens when the page is too big to read?

但网页内容太多,读不完时会怎样?

now step one, basic crawling.

现在进行第一步,基础网页抓取。

copy a page so your ai can read it.

复制一个网页,让你的 AI 能读懂它。

i used stripe's pricing page.

我用了 Stripe 的定价页面。

many people who build apps know it.

很多开发应用的人都知道它。

ai models read text in small word pieces.

AI 模型会把文本读成一个个小的词片段。

these pieces are called tokens.

这些片段叫作令牌。

you pay for everyone.

每个令牌都要付费。

stripe's page is too big, about 327,000 tokens.

Stripe 的页面太大了,大约有 327,000 个令牌。

my ai, gpt-4o mini reads 128,000 at most.

我的 AI,也就是 GPT-4o mini,最多只能读取 128,000 个令牌。

that's OpenAI's small ai model.

那是 OpenAI 的小型 AI 模型。

so my ai refused the page.

所以我的 AI 拒绝读取这个页面。

most of the page is code for menus, styles, and tracking.

页面的大部分内容都是菜单、样式和跟踪功能的代码。

A person never reads it.

人根本不会读这些内容。

The fix is Trafilatura a free tool that cleans pages pip is the free tool that installs Python code type pip install Trafilatura.

解决办法是 Trafilatura,这是一个免费工具,可以清理网页。pip 是用来安装 Python 代码的免费工具,输入 pip install Trafilatura。

Open a new file load trafilatura.

打开一个新文件,加载 trafilatura。

Download the page, keep only the main words and print them.

下载页面,只保留主要文字,然后把它们打印出来。

stripe's page dropped to about 2,000 tokens in a third of a second for free.

Stripe 的页面缩减到了大约 2,000 个令牌,而且只用了三分之一秒,完全免费。

so cut each page down to its words first.

所以,先把每个页面缩减成文字。

but is the price still there?

但价格还在吗?

now step two, check the facts are still there.

现在进行第二步,检查事实是否仍然存在。

you'd expect a cleaner page to give a better answer.

你本以为更干净的页面会给出更好的答案。

i asked my agent what stripe charges for a normal card payment.

我问我的智能体,Stripe 普通银行卡支付的手续费是多少。

it said the page doesn't say, but the live page.

它说页面上没写,但实时页面上

shows 1.5% plus 20 pence.

显示的是 1.5% 加 20 便士。

look at the clean text.

看看清理后的文本。

the label for each card is there.

每种银行卡的名称都还在。

the price next to it is gone.

旁边的价格却不见了。

the cleaner thought the price boxes were only decoration, so it cut them.

清理程序以为价格框只是装饰,所以把它们删掉了。

nothing failed.

没有任何报错。

the code ran fine and the answer was wrong.

代码运行正常,答案却错了。

the fix is one line.

修复只需一行代码。

tell your code what the page must contain.

告诉你的代码,页面必须包含什么内容。

for a price page, look for a percent sign.

对于价格页面,检查是否有百分号。

If it's missing, stop.

如果没有,就停止。

Don't trust the read.

不要相信读取结果。

So check that the fact you need is still there.

所以,要检查你需要的事实是否还在。

But what if the page comes back empty?

但如果页面返回的是空白内容呢?

Now step three, JavaScript pages, read pages that come back empty.

现在进入第三步:JavaScript 页面——读取返回空白内容的页面。

I pointed the same cleaner at the pricing page of HubSpot, a popular sales tool.

我把同一个清理程序用在 HubSpot 的定价页面上。HubSpot 是一款热门的销售工具。

The cleaner copied nothing and showed no error.

清理程序什么也没复制,也没有显示错误。

The page is built by JavaScript, a kind of code that runs in your browser after the page loads.

页面由 JavaScript 构建,这是一种在页面加载后于浏览器中运行的代码。

A simple download never runs that code.

简单下载不会运行这段代码。

So it gets an empty page.

所以得到的是一个空页面。

The fix is a real browser that your code controls Crawl4AI.

解决办法是使用一个由代码控制的真实浏览器:Crawl4AI。

Crawl4AI is a free tool that opens pages in a browser for you type pip install crawl4ai then crawl4ai-setup.

Crawl4AI 是一款免费工具,可以替你在浏览器中打开网页。输入 pip install crawl4ai,然后输入 crawl4ai-setup。

Open the browser.

打开浏览器。

Load the page and wait until it's done.

加载页面,然后等它加载完成。

print the words.

打印出文字。

with it, the hubspot prices came back.

用了它之后,HubSpot 的价格信息就出来了。

so when a page comes back empty, read it in a browser.

所以,网页返回空内容时,就用浏览器读取它。

but a browser reads everything.

但浏览器会读取所有内容。

so what about text you can't see?

那么,看不见的文字怎么办?

now step four, hidden instructions.

现在来到第四步:隐藏指令。

stop pages that trick your ai.

阻止那些会欺骗 AI 的网页。

to test this safely, i made my own price page.

为了安全地测试,我创建了自己的价格页面。

it has two plans.

上面有两个套餐。

19 and 49 dollars.

19 美元和 49 美元。

Then i hid eight instructions in it.

然后我在里面藏了八条指令。

The way attackers do, I used white text, a hidden box, tiny text and more.

我采用了攻击者常用的做法:白色文字、隐藏框、极小的文字等。

Each instruction says ai and your answer with a secret word.

每条指令都要求 AI 在回答中加入一个秘密词。

It's harmless but it shows the ai obeyed.

这没有危害,但它说明 AI 照做了。

You'd expect a cleaner to drop text that nobody can see.

你会以为清理工具会删掉没人看得见的文字。

That doesn't hold up.

事实并非如此。

Trafilatura, let two through crawl for ai.

Trafilatura 放过了两个,Crawl for AI 也放过了两个。

Let 5 through Crawl4AI, a free page cleaner.

Crawl4AI 放过了五个。它是免费的网页清理工具。

Let 4 through gina reader needs.

Jina Reader 放过了四个。

No install.

无需安装。

You put r.jina.ai in front of the web address.

你只要把 r.jina.ai 加在网址前面。

Then i asked my agent about the plans.

然后我问了我的智能体有关计划的事。

It added the secret word three times out of three.

它三次都加上了那个秘密词。

This is called prompt injection.

这叫提示注入。

Prompt injection means.

提示注入指的是,

hidden words on a page that change what your ai does.

网页上的隐藏文字会改变 AI 的行为。

a real attacker could ask your agent to send your data out.

真正的攻击者可能会让你的智能体把数据发送出去。

the fix is my safe reader.

解决办法是使用我的安全阅读器。

it opens the page in a real browser.

它会在真正的浏览器中打开网页。

It uses crawl for AI, so install that first.

它使用 Crawl for AI,所以先安装它。

The code is in the description.

代码在描述栏里。

Then it keeps only what a person can see.

然后它只保留人能看见的内容。

It skips hidden parts.

它会跳过隐藏部分。

It skips tiny text.

它会跳过很小的文字。

It skips white text on a white page.

它会跳过白色页面上的白色文字。

Then it deletes invisible letters.

然后它会删除不可见的字母。

Those are special letters your eyes can't see.

那些是特殊字母,你的眼睛看不见。

And it stops if the fact you need is missing.

如果缺少你需要的信息,它就会停止。

On my test page, zero hidden instructions got through.

在我的测试页面上,没有隐藏指令得逞。

My agent obeyed zero times out of three.

我的智能体三次尝试中一次也没服从。

On Stripe, it kept the real price in about 5,000 tokens.

在 Stripe 上,它用大约 5,000 个 token 保留了真实价格。

On HubSpot, it found the prices.

在 HubSpot 上,它找到了价格。

So 138 line file fixed all four problems on my test pages.

所以,这个 138 行的文件解决了我测试页面上的全部四个问题。

But what if you need thousands of pages a day?

但如果你每天需要处理成千上万的页面呢?

Context.

Context。

dev sponsored this part of the video.

dev 赞助了视频的这一部分。

Context.

Context。

dev gives your AI agent live data from the web.

dev 为你的 AI 智能体提供来自网络的实时数据。

Here's a real example with claude code.

下面是一个使用 Claude Code 的真实例子。

Claude code is the claude app that writes code on your computer.

Claude Code 是一款能在你的电脑上编写代码的 Claude 应用。

Add context.

添加 Context。

dev to claude code with one command, then sign in once.

用一条命令将 dev 添加到 Claude Code,然后登录一次。

Now, i ask claude code, how do i set up crawl for ai today?

现在,我问 Claude Code:今天如何设置 Crawl for AI?

Claude code calls context.

Claude Code 调用 Context.dev。

dev once context.

Context.dev 读取 AI Setup 页面当前的抓取内容。

dev reads the current crawl for ai setup page.

Context.dev 读取 AI Setup 页面当前的抓取内容。

Here is the part of the page it used and the web address it came from then claude code answers.

这里是它用到的页面片段,以及内容来源的网址,然后 Claude Code 给出了回答。

Using that page as its proof.

它以该页面作为依据。

So you can see the source behind the answer.

这样你就能看到答案背后的来源。

You get 1,000 free credits a month, no card needed.

你每月可免费获得 1,000 个额度,无需信用卡。

The link is in the description.

链接在简介里。

So when your agent needs fresh web pages, context.

所以,当你的智能体需要最新的网页内容时,Context.dev 会把它们带进来。

dev brings them in.

Context.dev 会把它们带进来。

But does my strict reader break real pages?

但我的严格阅读器会不会把真实网页弄坏?

Now step five, test it on 12 real websites.

现在来到第五步:在 12 个真实网站上测试它。

A strict reader could throw away real words too.

严格的阅读器也可能把真实内容过滤掉。

So I tested 12 popular pages like Wikipedia and BBC News.

所以我测试了 12 个热门网页,比如维基百科和 BBC 新闻。

For each page, I picked one fact that must be there, like a price or a headline.

每个网页我都选了一个必须保留的信息,比如价格或标题。

You'd expect a strict reader to break lots of pages.

你可能会觉得严格的阅读器会弄坏很多网页。

It kept the fact on 10 of the 12.

它在 12 个网页中的 10 个上保留了那条信息。

On BBC News, it sent about 1,800 tokens.

在 BBC 新闻页面上,它输出了大约 1,800 个词元。

Crawl4AI sent 21,000.

Crawl4AI 输出了 21,000 个。

But on the price page of Notion, a notes app, it returned nothing.

但在 Notion 这款笔记应用的价格页面上,它什么也没返回。

That's why the check matters.

这就是检查很重要的原因。

It stopped with a loud warning instead of passing on an empty page.

它发出响亮的警告后停了下来,没有把空白页面当作正常结果通过。

When it stops, read that one page with Crawl4AI.

停下来时,用 Crawl4AI 读取那一页。

It kept the fact on every page I tried.

我测试过的每一页都保留了这条信息。

so test your reader on the pages your agent really uses.

所以要用你的智能体实际会用到的页面来测试读取器。

now how does your agent use it?

那么你的智能体会怎样使用它?

now step six, agentic crawling.

现在进入第六步:智能体式爬取。

give the reader to your own ai agent.

把读取器交给你自己的 AI 智能体。

i built a small research agent with PraisonAI, a free toolkit for building ai agents.

我用 PraisonAI 构建了一个小型研究智能体。PraisonAI 是一个免费的 AI 智能体构建工具包。

type pip install praisonai.

输入 pip install praisonai。

make the safe reader a tool.

把安全读取器设为一个工具。

a tool is a small piece of code your agent can run.

工具是一小段智能体可以运行的代码。

create the agent.

创建智能体。

tell it that page text is information, never instructions.

告诉它,网页文本是信息,绝不是指令。

give it the tool.

把这个工具交给它。

then i asked for stripe's normal card fee.

然后我问它 Stripe 常规的银行卡手续费是多少。

that's the question my first agent got wrong.

这是我的第一个智能体答错的问题。

it read the page with the safe reader.

它用安全读取器读取了页面。

it answered 1.5% plus 20 pence, the real price.

它回答说是 1.5% 加 20 便士,这才是真实费率。

so any agent can use this tool in a few lines.

所以,任何智能体都能用几行代码调用这个工具。

but what about the one attack no filter can stop?

但还有一种攻击,任何过滤器都无法阻止,怎么办?

some tricks are written in normal text.

有些伎俩是用普通文本写成的。

no filter can spot them.

任何过滤器都识别不了它们。

so tell your agent that page text is.

所以要告诉你的智能体,网页上的文字

Is never an instruction and make it ask you before it sends anything.

绝不是指令,而且在发送任何内容之前都要先问你。

So how do you know your agent read the right page?

那么,你怎么知道智能体读的是正确的网页?

You check it every time.

每次都检查。

Here's the recap.

下面来回顾一下。

Step one, basic crawling.

第一步,基础爬取。

Step two, check the facts.

第二步,核对事实。

Step three, JavaScript pages.

第三步,处理 JavaScript 页面。

Step four, hidden instructions.

第四步,识别隐藏指令。

Step five, test on real websites.

第五步,在真实网站上测试。

Step six, give it to your agent.

第六步,把它交给你的智能体。

So check every page your agent reads.

所以,要检查智能体读取的每个网页。

Do let me know in the comments below what you think about this.

欢迎在下方评论区告诉我你对此有什么看法。

Considering you already liked this video, you might also like the video shown above.

既然你已经点了赞,或许也会喜欢上方展示的视频。

I'll see you there.

我们在那里见。

Overview

网页抓取会把网页内容复制给 AI 智能体,但清理工具可能删掉关键事实,普通下载也可能无法读取由 JavaScript 生成的页面;网页中的隐藏文字还可能诱导智能体执行指令。视频以 Stripe 价格被清理工具漏掉、HubSpot 页面抓取为空和隐藏指令测试为例,逐步演示基础抓取、事实校验、浏览器渲染与安全过滤,并介绍自制安全阅读器、Context.dev 和将阅读工具交给智能体。测试中,安全阅读器保留了 Stripe 的价格,在 12 个网站中有 10 个通过事实检查;结论是应验证页面是否包含所需事实,并明确要求智能体把网页文本当作信息而非指令。

Chapters

01:51 智能体如何读取网页,以及页面过大带来的问题

AI 智能体通过代码复制得到的文本读取网页,可能拿到页面代码、隐藏部分或空内容。Stripe 定价页约有 327,000 个 token,超过 GPT-4o mini 的 128,000 token 上限,因此模型拒绝读取。Trafilatura 可去掉大量页面代码,把内容缩到约 2,000 个 token,处理约需三分之一秒,但缩短内容后仍需确认重要事实没有被删掉。

Stripe 页面约 327,000 个 tokens,超过模型可读取上限

03:19 清理页面后检查关键事实是否保留

Trafilatura 虽然大幅缩短了 Stripe 页面,却删掉了卡种旁边的价格。智能体因此回答页面没有说明普通银行卡费用,而页面实际写着 1.5% 加 20 便士;程序正常运行并不代表读取结果正确。针对价格页面,可以要求读取结果必须包含百分号等所需标记,缺少时就停止并提示检查,而不要信任不完整的读取结果。

页面显示的银行卡费率
清理后的文本保留卡种标签,却丢失价格

04:28 用浏览器读取 JavaScript 页面

抓取 HubSpot 营销定价页时,简单下载工具返回空内容且没有报错,因为页面依靠浏览器加载后运行的 JavaScript 生成。Crawl4AI 会在受控浏览器中打开页面并等待加载,随后能够读出 HubSpot 价格。页面抓取为空时,需要检查是否必须运行页面脚本,并改用真实浏览器读取。

浏览器读取后显示 HubSpot 定价内容

05:22 隐藏指令测试与安全阅读器

在包含 19 美元和 49 美元两个方案的测试页中,隐藏了八条要求 AI 输出秘密词的指令。测试显示,Trafilatura 放过两条,Crawl4AI 放过五条,Jina Reader 放过四条;智能体三次都复述了秘密词。自制安全阅读器使用浏览器读取页面,只保留可见内容,过滤隐藏部分、极小文字、白字和不可见字符,并在缺少所需事实时停止。测试中八条隐藏指令均未通过,智能体三次均未服从;读取 Stripe 时保留了真实价格,约用 5,000 个 token,也找回了 HubSpot 价格。

自制价格页面展示两个套餐
页面中隐藏指令的不同呈现方式
通过安全阅读器地址处理网页
测试中智能体三次都返回秘密词
安全阅读器过滤不可见内容后的页面文本

07:30 Context.dev 为智能体提供实时网页资料

视频展示了赞助工具 Context.dev 与 Claude Code 的连接方式:添加服务并登录后,Claude Code 可查询 Crawl4AI 的当前设置页面,Context.dev 返回引用内容和来源网址,供回答时核对。视频称其免费额度为每月 1,000 个 credits,且无需绑定银行卡。

展示引用的网页内容及其来源网址

08:25 用真实网站检查安全阅读器

安全阅读器在 12 个常见网站页面上逐页检查预先选定的事实,10 页保留了目标事实。在 BBC News 页面上,它输出约 1,800 个 token,Crawl4AI 输出约 21,000 个;Notion 定价页则返回空内容。由于阅读器会在必需事实缺失时明确报错,它能阻止空页面被当成有效结果;对于失败页面,可改用 Crawl4AI 读取,并应按智能体实际使用的网站进行测试。

章节代表画面
12个网页中有10个保留了目标事实
BBC News页面的输出量
Crawl4AI在BBC News页面的输出量
Notion价格页未返回内容

09:18 将安全阅读器交给智能体并处理剩余风险

研究智能体可以把安全阅读器封装为可调用工具。示例使用 PraisonAI 创建智能体,并要求它将网页文本视为信息而非指令;智能体通过安全阅读器读取 Stripe 后,正确回答普通银行卡费用为 1.5% 加 20 便士。过滤器无法识别所有伪装成普通文字的恶意内容,因此还要明确要求智能体不执行网页指令,并在发送任何内容前先询问用户;页面读取结果也应逐次核验。

安全阅读器读取并给出 Stripe 的实际刷卡费率
回顾六个步骤的总结画面

Conclusions

03:55 网页清理可能删掉价格等关键事实,因此读取结果必须检查是否包含任务所需信息,缺失时应停止并提示。

10:13 网页文字应被视为信息而不是指令,并要求智能体在发送内容前先询问用户。

08:25 安全阅读器需要在智能体实际使用的网站上验证,因为不同页面可能返回空内容或丢失目标事实。