Update index.js
Browse files
index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
| 1 |
const puppeteer = require('puppeteer');
|
| 2 |
const express = require('express');
|
|
|
|
| 3 |
const app = express();
|
| 4 |
const port = 7860;
|
| 5 |
|
|
|
|
|
|
|
| 6 |
function convertEscapedUrlToStandard(escapedUrl) {
|
| 7 |
// 使用正则表达式替换所有的转义反斜杠
|
| 8 |
const standardUrl = escapedUrl.replace(/\\\//g, '/');
|
| 9 |
return standardUrl;
|
| 10 |
}
|
|
|
|
| 11 |
function extractStringAfterRp(url) {
|
| 12 |
// 分割URL并找到 'rp/' 后面的部分
|
| 13 |
const parts = url.split('rp/');
|
|
@@ -17,8 +21,6 @@ function extractStringAfterRp(url) {
|
|
| 17 |
return '未找到 "rp/" 后的字符串';
|
| 18 |
}
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
app.get('/*', async (req, res) => {
|
| 23 |
const referer = req.headers.referer || "https://r.bing.com";
|
| 24 |
const url = new URL(referer);
|
|
@@ -45,27 +47,26 @@ app.get('/*', async (req, res) => {
|
|
| 45 |
const htmlContent = document.documentElement.innerHTML;
|
| 46 |
const matchcib = htmlContent.match(regex);
|
| 47 |
if (matchcib) {
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
const matches = htmlContent.match(allregex)
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
}
|
| 63 |
return { scripts: '没有找到匹配的字符串', cibname, htmlContent };
|
| 64 |
});
|
| 65 |
|
| 66 |
console.log(result.cibname); // 在此处输出 htmlContent
|
| 67 |
|
| 68 |
-
// 判断访问路径
|
| 69 |
if (req.path === '/html') {
|
| 70 |
res.set('Content-Type', 'text/html');
|
| 71 |
res.send(result.htmlContent); // 发送 htmlContent 的纯文本响应
|
|
@@ -85,7 +86,7 @@ app.get('/*', async (req, res) => {
|
|
| 85 |
res.set('Content-Type', 'text/plain');
|
| 86 |
res.send('没有找到Core匹配的字符串');
|
| 87 |
}
|
| 88 |
-
|
| 89 |
// 提取以 <script type="importmap" nonce=""> 开始,以 </script> 结尾的字符串
|
| 90 |
const importmapContent = result.htmlContent.match(/<script type="importmap" nonce="">.*?<\/script>/s);
|
| 91 |
if (importmapContent) {
|
|
@@ -104,15 +105,8 @@ app.get('/*', async (req, res) => {
|
|
| 104 |
|
| 105 |
// 关闭浏览器
|
| 106 |
await browser.close();
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
// const standardUrl = convertEscapedUrlToStandard(result);
|
| 110 |
-
// const stringAfterRp = extractStringAfterRp(standardUrl);
|
| 111 |
-
// 将结果发送回客户端
|
| 112 |
-
// res.send(stringAfterRp);
|
| 113 |
});
|
| 114 |
|
| 115 |
-
|
| 116 |
app.listen(port, () => {
|
| 117 |
console.log(`Server running at http://localhost:${port}`);
|
| 118 |
-
});
|
|
|
|
| 1 |
const puppeteer = require('puppeteer');
|
| 2 |
const express = require('express');
|
| 3 |
+
const cors = require('cors'); // 引入 cors 中间件
|
| 4 |
const app = express();
|
| 5 |
const port = 7860;
|
| 6 |
|
| 7 |
+
app.use(cors()); // 使用 cors 中间件
|
| 8 |
+
|
| 9 |
function convertEscapedUrlToStandard(escapedUrl) {
|
| 10 |
// 使用正则表达式替换所有的转义反斜杠
|
| 11 |
const standardUrl = escapedUrl.replace(/\\\//g, '/');
|
| 12 |
return standardUrl;
|
| 13 |
}
|
| 14 |
+
|
| 15 |
function extractStringAfterRp(url) {
|
| 16 |
// 分割URL并找到 'rp/' 后面的部分
|
| 17 |
const parts = url.split('rp/');
|
|
|
|
| 21 |
return '未找到 "rp/" 后的字符串';
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
| 24 |
app.get('/*', async (req, res) => {
|
| 25 |
const referer = req.headers.referer || "https://r.bing.com";
|
| 26 |
const url = new URL(referer);
|
|
|
|
| 47 |
const htmlContent = document.documentElement.innerHTML;
|
| 48 |
const matchcib = htmlContent.match(regex);
|
| 49 |
if (matchcib) {
|
| 50 |
+
const cibname = matchcib[0];
|
| 51 |
+
// 使用正则表达式提取所有的JS文件URL
|
| 52 |
+
const allregex = /\/([a-zA-Z0-9_-]+\.br\.js)'/g;
|
| 53 |
+
const matches = htmlContent.match(allregex);
|
|
|
|
| 54 |
|
| 55 |
+
let scripts = '';
|
| 56 |
+
if (matches) {
|
| 57 |
+
matches.forEach(match => {
|
| 58 |
+
const scriptUrl = match.replace(/'/g, "");
|
| 59 |
+
scripts += `<script src="https://r.bing.com/rp${scriptUrl}"></script>\n`;
|
| 60 |
+
});
|
| 61 |
+
}
|
| 62 |
+
return { scripts, cibname, htmlContent };
|
| 63 |
}
|
| 64 |
return { scripts: '没有找到匹配的字符串', cibname, htmlContent };
|
| 65 |
});
|
| 66 |
|
| 67 |
console.log(result.cibname); // 在此处输出 htmlContent
|
| 68 |
|
| 69 |
+
// 判断访问路径
|
| 70 |
if (req.path === '/html') {
|
| 71 |
res.set('Content-Type', 'text/html');
|
| 72 |
res.send(result.htmlContent); // 发送 htmlContent 的纯文本响应
|
|
|
|
| 86 |
res.set('Content-Type', 'text/plain');
|
| 87 |
res.send('没有找到Core匹配的字符串');
|
| 88 |
}
|
| 89 |
+
} else if (req.path === '/importmap') {
|
| 90 |
// 提取以 <script type="importmap" nonce=""> 开始,以 </script> 结尾的字符串
|
| 91 |
const importmapContent = result.htmlContent.match(/<script type="importmap" nonce="">.*?<\/script>/s);
|
| 92 |
if (importmapContent) {
|
|
|
|
| 105 |
|
| 106 |
// 关闭浏览器
|
| 107 |
await browser.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
});
|
| 109 |
|
|
|
|
| 110 |
app.listen(port, () => {
|
| 111 |
console.log(`Server running at http://localhost:${port}`);
|
| 112 |
+
});
|