如何抓取已禁用 DevTools 的网站

问题描述 投票:0回答:1

如何抓取已禁用 Chrome DevTools 的网站?

使用 Puppeteer,我尝试使用各自的 CSS 选择器获取特定航空公司的出发和到达时间,但由于 DevTool 被禁用而没有成功。

经过一番检查,与 Facebook 的做法类似,我发现该网站禁用了 DevTools(Puppeteer 控制浏览器的协议)。我似乎无法在控制台中运行任何有效的 JavaScript 函数。

请问有什么方法可以抓取这样的网站吗?

更新

事实证明,该网站加载了下面的 JavaScript 函数,这限制了我在控制台中运行任何有效 JavaScript 代码的能力。

function preventAction(a) {
  a.preventDefault();
  return false
}
jQuery(function() {
  $(document).on("paste", "input", preventAction);
  $(document).on("drop", "input", preventAction);
  $("html").css({
    userSelect: "none"
  })
});
$(function() {
  var c = 0;
  function b() {
    if (!c) {
      setTimeout(function() {
        console.warn("%cYou are not allowed to use developer tools in Production mode!", "font: 2em sans-serif; color: yellow; background-color: red;")
      }, 1);
      c = 1
    }
    throw "Console is disabled!"
  }
  var a, d = {
    set: function(e) {
      a = e
    },
    get: function() {
      b();
      return a
    }
  };
  console.log("2016 Hitit Computer Services");
  console.warn("%cYou are not allowed to use developer tools in Production mode!", "font: 2em sans-serif; color: #fefefe; background-color: #B5121B; padding: 4px;");
  Object.defineProperty(console, "_commandLineAPI", d);
  Object.defineProperty(console, "__commandLineAPI", d);
  Object.defineProperty(window, "_commandLineAPI", d);
  Object.defineProperty(window, "__commandLineAPI", d);
  Object.defineProperty(window, "console", d)
});

有没有办法使用 Puppeteer 覆盖网站加载的函数

Object.defineProperty(console,"_commandLineAPI",d)
,以便我可以使用 Cheerio 遍历 DOM 树?

javascript web-scraping google-chrome-devtools puppeteer cheerio
1个回答
0
投票

以下是如何在阻止/阻止打开 DevTools 的网站上打开 DevTools:

  1. 查看目标站点时...

  2. 在同一选项卡上,导航到允许使用 DevTools 的不同站点

  3. 打开开发工具

  4. 按后退按钮返回目标站点

  5. DevTools 应更新以显示目标站点

达达!

(2024 年 5 月 16 日在 app.smartsheet.com 上测试)

© www.soinside.com 2019 - 2024. All rights reserved.