بنقرة واحدة
html-parser-rule
编写与测试 HTML 解析规则。用于从网页提取文章标题、链接、日期等信息。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
编写与测试 HTML 解析规则。用于从网页提取文章标题、链接、日期等信息。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | html-parser-rule |
| description | 编写与测试 HTML 解析规则。用于从网页提取文章标题、链接、日期等信息。 |
This skill helps you write and test HTML parsing rules for article-flow project. It follows a systematic approach:
When user provides a URL to parse, first fetch and save the HTML:
# Fetch HTML and save to temporary file
curl -L -H "User-Agent: Mozilla/5.0" "{URL}" > /tmp/source.html
# Show file size and first 100 lines to understand structure
wc -l /tmp/source.html
head -100 /tmp/source.html
Ask user to confirm the HTML looks correct and identify the article listing structure.
Examine the HTML structure and identify:
Show the user example HTML snippets and ask for confirmation.
Create and test the title extraction regex:
// Example title regex
const titleRegex = /<h2[^>]*><a[^>]*>([^<]+)<\/a><\/h2>/g;
Test it immediately:
# Test title regex in Node.js
node -e "
const fs = require('fs');
const html = fs.readFileSync('/tmp/source.html', 'utf-8');
const titleRegex = /<h2[^>]*><a[^>]*>([^<]+)<\/a><\/h2>/g;
const matches = [...html.matchAll(titleRegex)];
console.log('Found', matches.length, 'titles:');
matches.slice(0, 5).forEach((m, i) => console.log(i+1, m[1]));
"
Wait for user confirmation before proceeding.
Create and test the link extraction regex:
// Example link regex
const linkRegex = /<a[^>]*href="([^"]+)"[^>]*>.*?<\/a>/g;
Test it:
node -e "
const fs = require('fs');
const html = fs.readFileSync('/tmp/source.html', 'utf-8');
const linkRegex = /<a[^>]*href=\"([^\"]+)\"[^>]*>/g;
const matches = [...html.matchAll(linkRegex)];
console.log('Found', matches.length, 'links:');
matches.slice(0, 5).forEach((m, i) => console.log(i+1, m[1]));
"
Wait for user confirmation before proceeding.
If the source has date information, create and test:
// Example date regex
const dateRegex = /<time[^>]*datetime="([^"]+)"[^>]*>/g;
Test it:
node -e "
const fs = require('fs');
const html = fs.readFileSync('/tmp/source.html', 'utf-8');
const dateRegex = /<time[^>]*datetime=\"([^\"]+)\"[^>]*>/g;
const matches = [...html.matchAll(dateRegex)];
console.log('Found', matches.length, 'dates:');
matches.slice(0, 5).forEach((m, i) => console.log(i+1, m[1]));
"
If the source has description/summary, create and test:
// Example description regex
const descRegex = /<p class="excerpt">([^<]+)<\/p>/g;
Test it similarly.
Now create the complete parser function in the html-parser.ts file:
/**
* Parse {SOURCE_NAME}
*/
private parseSourceName(html: string, source: DataSource): ContentItem[] {
const items: ContentItem[] = [];
// Your regex patterns
const titleRegex = /pattern/g;
const linkRegex = /pattern/g;
const dateRegex = /pattern/g;
const descRegex = /pattern/g;
// Extract all matches
const titles = [...html.matchAll(titleRegex)];
const links = [...html.matchAll(linkRegex)];
const dates = [...html.matchAll(dateRegex)];
const descs = [...html.matchAll(descRegex)];
// Combine into items
const maxLength = Math.max(titles.length, links.length);
for (let i = 0; i < maxLength; i++) {
const title = titles[i]?.[1];
const link = links[i]?.[1];
const date = dates[i]?.[1];
const desc = descs[i]?.[1];
if (title && link) {
items.push({
title: this.decodeHtml(title.trim()),
link: this.resolveUrl(link, source.url),
source: source.name,
sourceUrl: source.url,
isoDate: date ? new Date(date).toISOString() : undefined,
contentSnippet: desc ? this.decodeHtml(desc.trim()) : undefined
});
}
}
return items;
}
Add the parser to the parse() method's switch statement:
case "source-name":
return this.parseSourceName(html, source);
Add the source to the domain configuration:
{
name: "Source Name",
url: "https://...",
type: "html",
parser: "source-name",
tags: ["tag1", "tag2"]
}
Run the full collection to test:
cd packages/ai-digest
pnpm run collect
Check the report to verify:
Examine the output files:
# Check if articles from this source appear in output
grep "Source Name" outputs/$(date +%Y-%m-%d).en.md
If all tests pass, the parser rule is complete!
// Often structured as:
// <article>
// <h2><a href="...">Title</a></h2>
// <time datetime="...">Date</time>
// <p>Description</p>
// </article>
// Often structured as:
// <div class="article">
// <a href="...">
// <h3>Title</h3>
// </a>
// <span class="date">Date</span>
// <div class="summary">Description</div>
// </div>
// Often uses JSON-LD structured data:
const scriptRegex = /<script type="application\/ld\+json">(.*?)<\/script>/gs;
// Then parse the JSON
User: "编写html解析规则 https://venturebeat.com/"
Generate a project-specific AGENTS.md draft from the current repository when the user asks to initialize, create, rewrite, or refine AGENTS.md for this repo. Use when the user wants only repo-specific instructions, not generic coding rules. This skill must inspect the current repository, extract its local conventions and boundaries, present a draft first, and wait for user confirmation before writing or overwriting AGENTS.md.
Generic memory and self-improvement skill for user-level or project-level contexts. Use when the user wants Codex to remember stable preferences, workflow patterns, repeated failures, or durable context; when checking whether memory/automation/AGENTS are initialized; when initializing memory infrastructure in ~/.codex or a project root; or when listing, deleting, clearing, or promoting memory records.
小红书爆款文案助手。将技术或职场经历转化为情感共鸣强、极具传播力的故事。遵循S.L.R.A.模型。
将Markdown批量导出固定尺寸的小红书长文图片。适用"md转图片/转小红书长文图"。
skill查询与管理。列出所有可用skill清单,搜索及查看skill详细用法。
将 Markdown 转为适合小红书粘贴的纯文本(去掉