如何以编程方式在URL上执行javascript

How to execute javascript on a URL programmatically

本文关键字:URL 执行 javascript 方式 编程      更新时间:2023-09-26

我想使用Readability的javascript来清理新闻文章,然后下载生成的文章。这需要能够执行他们的js代码:

window.baseUrl          = 'https://www.readability.com';
window.readabilityToken = '';
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('charset','UTF-8');
s.setAttribute('src', baseUrl + '/bookmarklet/read.js');
document.documentElement.appendChild(s);

在不同于传统 Web 浏览器的环境中。例如,这可以通过使用Firebug在站点上执行上述代码来实现;我想通过Java(没有浏览器)模拟该功能。 我在这里看到的问题之一是"窗口"对象,在以编程方式访问页面时可能不存在。

关于这是否可行以及如何实施的任何提示?

看看一个无头浏览器,比如EnvJS。