Files
ruoyi-java/test_parse.html
2025-10-10 02:07:29 +08:00

76 lines
2.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<title>线报解析测试</title>
</head>
<body>
<h2>线报解析测试</h2>
<textarea id="message" rows="10" cols="80" placeholder="请输入线报消息">
【京东】iPhone 15 Pro Max
https://item.jd.com/100012345678.html
到手价7999元
【京东】MacBook Pro
https://item.jd.com/100087654321.html
到手价12999元
SKUID: 1000987654321
</textarea>
<br><br>
<button onclick="testParse()">测试解析</button>
<div id="result"></div>
<script>
function testParse() {
const message = document.getElementById('message').value;
const resultDiv = document.getElementById('result');
// 京东链接正则表达式
const jdUrlPattern = /https?:\/\/[^\s]*?jd\.com[^\s]*/g;
// SKUID正则表达式10-13位数字
const skuidPattern = /\b(\d{10,13})\b/g;
// 提取URLs
const urls = [];
let match;
while ((match = jdUrlPattern.exec(message)) !== null) {
let url = match[0];
url = url.replace(/[\s,,。!?]+$/, '');
if (!urls.includes(url)) {
urls.push(url);
}
}
// 提取SKUIDs
const skuids = [];
while ((match = skuidPattern.exec(message)) !== null) {
const skuid = match[1];
if (skuid.length >= 11) {
skuids.push(skuid);
}
}
// 从URL中提取SKUID
for (const url of urls) {
const skuidMatch = url.match(/item\.jd\.com\/(\d+)\.html/);
if (skuidMatch) {
const skuid = skuidMatch[1];
if (!skuids.includes(skuid)) {
skuids.push(skuid);
}
}
}
resultDiv.innerHTML = `
<h3>解析结果:</h3>
<p><strong>提取到 ${urls.length} 个URL</strong></p>
<ul>${urls.map(url => `<li>${url}</li>`).join('')}</ul>
<p><strong>提取到 ${skuids.length} 个SKUID</strong></p>
<ul>${skuids.map(skuid => `<li>${skuid}</li>`).join('')}</ul>
`;
}
</script>
</body>
</html>