|
const puppeteer = require('puppeteer'); |
|
const express = require('express'); |
|
const app = express(); |
|
const port = 7860; |
|
|
|
function convertEscapedUrlToStandard(escapedUrl) { |
|
|
|
const standardUrl = escapedUrl.replace(/\\\//g, '/'); |
|
return standardUrl; |
|
} |
|
function extractStringAfterRp(url) { |
|
|
|
const parts = url.split('rp/'); |
|
if (parts.length > 1) { |
|
return parts[1]; |
|
} |
|
return '未找到 "rp/" 后的字符串'; |
|
} |
|
|
|
|
|
|
|
app.get('/', async (req, res) => { |
|
|
|
const browser = await puppeteer.launch({ |
|
executablePath: '/usr/bin/google-chrome-stable', |
|
|
|
}); |
|
|
|
const page = await browser.newPage(); |
|
|
|
|
|
await page.goto('https://www.bing.com/search?q=Microsoft+Copilot&FORM=hpcodx&showconv=1&showconv=1'); |
|
|
|
|
|
await page.waitForFunction(() => { |
|
return document.documentElement.innerHTML.includes('CodexBundle'); |
|
}, { timeout: 30000 }); |
|
|
|
|
|
const result = await page.evaluate(() => { |
|
const regex = /CodexBundle:cib-bundle.*?\.js/; |
|
const htmlContent = document.documentElement.innerHTML; |
|
const matchcib = htmlContent.match(regex); |
|
if (matchcib) { |
|
|
|
|
|
const allregex = /\/([a-zA-Z0-9_-]+\.br\.js)'/g |
|
const matches = text.match(allregex) |
|
|
|
let scripts = '' |
|
if (matches) { |
|
matches.forEach(match => { |
|
const scriptUrl = match.replace(/'/g, "") |
|
scripts += `<script src="https://sokwith-proxybing.hf.space/rp${scriptUrl}"></script>\n` |
|
}) |
|
} |
|
return scripts; |
|
} |
|
return '没有找到匹配的字符串'; |
|
}); |
|
|
|
console.log(result); |
|
|
|
await browser.close(); |
|
res.send(result); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
app.listen(port, () => { |
|
console.log(`Server running at http://localhost:${port}`); |
|
}); |