1
This commit is contained in:
75
test_parse.html
Normal file
75
test_parse.html
Normal file
@@ -0,0 +1,75 @@
|
||||
<!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>
|
||||
Reference in New Issue
Block a user