【问题标题】:Is it possible to retrieve the results of a console command for a remote website?是否可以检索远程网站的控制台命令的结果?
【发布时间】:2021-01-16 09:33:58
【问题描述】:

例如:

如果我转到https://www.yahoo.com,请在任何浏览器控制台中输入以下控制台命令:

localStorage.length

我会得到: 2

是否可以使用任何脚本语言来完成以上任务?

伪代码:(我这里使用curl,但是我在任何curl文档中都没有看到任何执行控制台命令的选项,所以这可能是不正确的)

    curl ("https://wwww.yahoo.com");  // establish connection to a remote site
    curl (execute console command: "localStorage.length" );  // execute console command like you would on the yahoo site
    echo (display results);  // which should be "2" in this example
    curl close; 

【问题讨论】:

  • curl 不会运行任何 JavaScript 代码。它只是向服务器询问资源并将其提供给您 - 它不会也无法在页面或类似页面上执行脚本。
  • 你可以使用类似github.com/puppeteer/puppeteer

标签: javascript python php web curl


【解决方案1】:

您正在寻找一种“headless browser”类型的工具,可以让您编写交互脚本,puppeteer 或类似的工具。这些工具的行为就像网络浏览器一样,只是没有任何 UI。因此,您可以让他们导航到某个页面,然后您可以像在该页面上运行一样运行代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-23
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    相关资源
    最近更新 更多