File size: 2,391 Bytes
55dde61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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) {
  // 分割URL并找到 'rp/' 后面的部分
  const parts = url.split('rp/');
  if (parts.length > 1) {
    return parts[1]; // 返回 'rp/' 后面的字符串
  }
  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');
  
  // 等待页面源码中出现 'CodexBundle' 字符串,最长等待时间为30秒
  await page.waitForFunction(() => {
    return document.documentElement.innerHTML.includes('CodexBundle');
  }, { timeout: 30000 }); // 设置超时时间为30秒
  
  // 执行页面脚本来查找特定的字符串
  const result = await page.evaluate(() => {
    const regex = /CodexBundle:cib-bundle.*?\.js/;
    const htmlContent = document.documentElement.innerHTML;
    const matchcib = htmlContent.match(regex);
    if (matchcib) {
        //   return matchcib[0];
        // 使用正则表达式提取所有的JS文件URL
        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);

//  const standardUrl = convertEscapedUrlToStandard(result);
//  const stringAfterRp = extractStringAfterRp(standardUrl);
  // 将结果发送回客户端
//  res.send(stringAfterRp);
});


app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);
});