【问题标题】:Using wappalyzer and puppeteer in node.js在 node.js 中使用 wappalyzer 和 puppeteer
【发布时间】:2022-07-07 00:38:38
【问题描述】:

我正在尝试构建一个爬虫来自动监控 Web 项目。

到目前为止一切顺利,脚本正在运行,但现在我想添加一个功能,自动分析我在项目中使用了哪些库。这项工作最强大的脚本是 wappalyser。他们有一个节点包 (https://www.npmjs.com/package/wappalyzer),上面写着你可以将它与 pupperteer 结合使用。

我设法运行了 pupperteer 并在控制台中记录了站点的源代码,但我没有正确的方法将源代码传递给 wappalyzer 分析函数。

你们有什么提示吗?

我尝试了这段代码,但得到一个 TypeError: url.split is not a function

function getLibarys(url) {

  (async () => {
    const browser = await puppeteer.launch({ headless: true });
    const page = await browser.newPage();
    await page.goto(url);

// get source code with puppeteer
const html = await page.content();

const wappalyzer = new Wappalyzer();

(async function () {
  try {
    await wappalyzer.init()

    // Optionally set additional request headers
    const headers = {}

    const site = await wappalyzer.open(page, headers)

    // Optionally capture and output errors
    site.on('error', console.error)

    const results = await site.analyze()

    console.log(JSON.stringify(results, null, 2))
  } catch (error) {
    console.error(error)
  }

  await wappalyzer.destroy()
})()
await browser.close()
  })()
} 

【问题讨论】:

    标签: javascript node.js web-scraping


    【解决方案1】:

    使用 wappalyzer 的示例代码修复它。

    function getLibarys(url) {
    
    
    const Wappalyzer = require('wappalyzer');
    
     
      const options = {
        debug: false,
        delay: 500,
        headers: {},
        maxDepth: 3,
        maxUrls: 10,
        maxWait: 5000,
        recursive: true,
        probe: true,
        proxy: false,
        userAgent: 'Wappalyzer',
        htmlMaxCols: 2000,
        htmlMaxRows: 2000,
        noScripts: false,
        noRedirect: false,
      };
      
      const wappalyzer = new Wappalyzer(options)
      
      ;(async function() {
        try {
          await wappalyzer.init()
    
    
      // Optionally set additional request headers
      const headers = {}
    
      const site = await wappalyzer.open(url, headers)
    
      // Optionally capture and output errors
      site.on('error', console.error)
    
      const results = await site.analyze()
    
      console.log(JSON.stringify(results, null, 2))
    } catch (error) {
      console.error(error)
    }
    
    await wappalyzer.destroy()
      })()
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-27
      • 2021-03-02
      • 2022-01-26
      • 2023-03-28
      • 1970-01-01
      • 2019-02-09
      • 2019-07-29
      • 1970-01-01
      相关资源
      最近更新 更多