Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🌐 chore: translate non-English comments to English in packages/web-crawler (#10101)

LobeHub Botbd4ee89a4345
diff --git a/packages/web-crawler/src/crawImpl/browserless.ts b/packages/web-crawler/src/crawImpl/browserless.ts
index 6753b43a88b..1268e3b90b1 100644
--- a/packages/web-crawler/src/crawImpl/browserless.ts
+++ b/packages/web-crawler/src/crawImpl/browserless.ts
@@ -56,7 +56,7 @@ export const browserless: CrawlImpl = async (url, { filterOptions }) => {
if (
!!result.content &&
result.title &&
- // Just a moment... 说明被 CF 拦截了
+ // "Just a moment..." indicates being blocked by CloudFlare
result.title.trim() !== 'Just a moment...'
) {
return {
diff --git a/packages/web-crawler/src/crawImpl/naive.ts b/packages/web-crawler/src/crawImpl/naive.ts
index 6b7063cfcca..eecd46301ae 100755
--- a/packages/web-crawler/src/crawImpl/naive.ts
+++ b/packages/web-crawler/src/crawImpl/naive.ts
@@ -6,25 +6,25 @@ import { htmlToMarkdown } from '../utils/htmlToMarkdown';
import { DEFAULT_TIMEOUT, withTimeout } from '../utils/withTimeout';
const mixinHeaders = {
- // 接受的内容类型
+ // Accepted content types
'Accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
- // 接受的编码方式
+ // Accepted encoding methods
'Accept-Encoding': 'gzip, deflate, br',
- // 接受的语言
+ // Accepted languages
'Accept-Language': 'en-US,en;q=0.9,zh;q=0.8',
- // 缓存控制
+ // Cache control
'Cache-Control': 'max-age=0',
- // 连接类型
+ // Connection type
'Connection': 'keep-alive',
- // 表明请求来自哪个站点
+ // Indicates which site the request is from
'Referer': 'https://www.google.com/',
- // 升级不安全请求
+ // Upgrade insecure requests
'Upgrade-Insecure-Requests': '1',
- // 模拟真实浏览器的 User-Agent
+ // Simulate real browser User-Agent
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
- // 防止跨站请求伪造
+ // Prevent cross-site request forgery
'sec-ch-ua': '"Google Chrome";v="121", "Not A(Brand";v="99", "Chromium";v="121"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
diff --git a/packages/web-crawler/src/crawler.ts b/packages/web-crawler/src/crawler.ts
index 9509a30a825..e2f36a556eb 100644
--- a/packages/web-crawler/src/crawler.ts
+++ b/packages/web-crawler/src/crawler.ts
@@ -19,8 +19,8 @@ export class Crawler {
}
/**
- * 爬取网页内容
- * @param options 爬取选项
+ * Crawl webpage content
+ * @param options Crawl options
*/
async crawl({
url,
@@ -31,14 +31,14 @@ export class Crawler {
impls?: CrawlImplType[];
url: string;
}): Promise<CrawlUniformResult> {
- // 应用URL规则
+ // Apply URL rules
const {
transformedUrl,
filterOptions: ruleFilterOptions,
impls: ruleImpls,
} = applyUrlRules(url, crawUrlRules);
- // 合并用户提供的过滤选项和规则中的过滤选项,用户选项优先
+ // Merge user-provided filter options and rule filter options, user options take priority
const mergedFilterOptions = {
...ruleFilterOptions,
...userFilterOptions,
@@ -53,7 +53,7 @@ export class Crawler {
? (userImpls.filter((impl) => Object.keys(crawlImpls).includes(impl)) as CrawlImplType[])
: systemImpls;
- // 按照内置的实现顺序依次尝试
+ // Try each implementation in the built-in order
for (const impl of finalImpls) {
try {
const res = await crawlImpls[impl](transformedUrl, { filterOptions: mergedFilterOptions });
diff --git a/packages/web-crawler/src/urlRules.ts b/packages/web-crawler/src/urlRules.ts
index 12735b420f8..e6fb6332309 100644
--- a/packages/web-crawler/src/urlRules.ts
+++ b/packages/web-crawler/src/urlRules.ts
@@ -1,32 +1,32 @@
import { CrawlUrlRule } from './type';
export const crawUrlRules: CrawlUrlRule[] = [
- // 搜狗微信链接,使用 search1api
+ // Sogou WeChat links, use search1api
{
impls: ['search1api'],
urlPattern: 'https://weixin.sogou.com/link(.*)',
},
- // 搜狗链接,使用 search1api
+ // Sogou links, use search1api
{
impls: ['search1api'],
urlPattern: 'https://sogou.com/link(.*)',
},
- // YouTube 链接,使用 search1api,格式化 markdown,且可以返回字幕内容
+ // YouTube links, use search1api, formatted as markdown, can return subtitle content
{
impls: ['search1api'],
urlPattern: 'https://www.youtube.com/watch(.*)',
},
- // Reddit 链接,使用 search1api,格式化 markdown,包含标题、作者、互动数量、具体评论内容等
+ // Reddit links, use search1api, formatted as markdown, includes title, author, interaction count, specific comment content, etc.
{
impls: ['search1api'],
urlPattern: 'https://www.reddit.com/r/(.*)/comments/(.*)',
},
- // 微信公众号有爬虫防护,优先使用 search1api,jina 作为兜底(目前 jina 爬取会被风控)
+ // WeChat official accounts have crawler protection, use search1api first, jina as fallback (currently jina crawling may be blocked)
{
impls: ['search1api', 'jina'],
urlPattern: 'https://mp.weixin.qq.com(.*)',
},
- // github 源码解析
+ // GitHub source code parsing
{
filterOptions: {
enableReadability: false,
@@ -43,7 +43,7 @@ export const crawUrlRules: CrawlUrlRule[] = [
// GitHub discussion
urlPattern: 'https://github.com/(.*)/discussions/(.*)',
},
- // 所有 PDF 都用 jina
+ // All PDFs use jina
{
impls: ['jina'],
urlPattern: 'https://(.*).pdf',
@@ -53,7 +53,7 @@ export const crawUrlRules: CrawlUrlRule[] = [
impls: ['jina'],
urlPattern: 'https://arxiv.org/pdf/(.*)',
},
- // 知乎有爬虫防护,使用 jina
+ // Zhihu has crawler protection, use jina
{
impls: ['jina'],
urlPattern: 'https://zhuanlan.zhihu.com(.*)',
@@ -63,7 +63,7 @@ export const crawUrlRules: CrawlUrlRule[] = [
urlPattern: 'https://zhihu.com(.*)',
},
{
- // Medium 文章转换为 Scribe.rip
+ // Convert Medium articles to Scribe.rip
urlPattern: 'https://medium.com/(.*)',
urlTransform: 'https://scribe.rip/$1',
},
@@ -74,10 +74,10 @@ export const crawUrlRules: CrawlUrlRule[] = [
impls: ['jina', 'browserless'],
urlPattern: 'https://(twitter.com|x.com)/(.*)',
},
- // 体育数据网站规则
+ // Sports data website rules
{
filterOptions: {
- // 对体育数据表格禁用 Readability 并且转换为纯文本
+ // Disable Readability for sports data tables and convert to plain text
enableReadability: false,
pureText: true,
},
@@ -94,13 +94,13 @@ export const crawUrlRules: CrawlUrlRule[] = [
impls: ['jina'],
urlPattern: 'https://cvpr.thecvf.com(.*)',
},
- // 飞书用 jina
+ // Feishu use jina
// https://github.com/lobehub/lobe-chat/issues/6879
{
impls: ['jina'],
urlPattern: 'https://(.*).feishu.cn/(.*)',
},
- // 小红书存在爬虫防护,使用 Search1API 或 Jina (备用)
+ // Xiaohongshu has crawler protection, use Search1API or Jina (fallback)
{
impls: ['search1api', 'jina'],
urlPattern: 'https://(.*).xiaohongshu.com/(.*)',
diff --git a/packages/web-crawler/src/utils/appUrlRules.ts b/packages/web-crawler/src/utils/appUrlRules.ts
index a47bb04cd85..8ff3fe33ed3 100644
--- a/packages/web-crawler/src/utils/appUrlRules.ts
+++ b/packages/web-crawler/src/utils/appUrlRules.ts
@@ -9,14 +9,14 @@ export const applyUrlRules = (
transformedUrl: string;
} => {
for (const rule of urlRules) {
- // 转换为正则表达式
+ // Convert to regular expression
const regex = new RegExp(rule.urlPattern);
const match = url.match(regex);
if (match) {
if (rule.urlTransform) {
- // 如果有转换规则,进行 URL 转换
- // 替换 $1, $2 等占位符为捕获组内容
+ // If there is a transformation rule, perform URL transformation
+ // Replace placeholders like $1, $2 with capture group content
const transformedUrl = rule.urlTransform.replaceAll(
/\$(\d+)/g,
(_, index) => match[parseInt(index)] || '',
@@ -28,7 +28,7 @@ export const applyUrlRules = (
transformedUrl,
};
} else {
- // 没有转换规则但匹配了模式,只返回过滤选项
+ // No transformation rule but pattern matched, only return filter options
return {
filterOptions: rule.filterOptions,
impls: rule.impls,
@@ -38,6 +38,6 @@ export const applyUrlRules = (
}
}
- // 没有匹配任何规则,返回原始 URL
+ // No rule matched, return original URL
return { transformedUrl: url };
};