[英]Is it possible to load external javascript files (from URLs) from the console, in chrome?
I want to semi-automate some actions. 我想半自动化一些动作。
I want the JQuery library to be loaded in a certain page, to allow me to easier manipulate/query the DOM, to get some data. 我希望将JQuery库加载到某个页面中,以允许我更轻松地操作/查询DOM,以获取一些数据。 The page is not under my control, but I don't want to write a crawler for it....I just want to manually crawl the data, from the console.
该页面不受我的控制,但是我不想为此编写爬虫...。我只想从控制台手动爬取数据。
Can I somehow make my console download and execute the script here "" https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js "? 我可以通过某种方式使控制台下载并在此处执行脚本““ https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js ”吗?
If not, why not? 如果没有,为什么不呢?
You can make your console download and execute scripts by appending a script
tag with the src
of the script. 您可以通过在
script
的src
后面附加script
标签来使控制台下载并执行脚本。
var scriptTag = document.createElement("script");
scriptTag.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js");
document.body.appendChild(scriptTag);
Yes, you can. 是的你可以。 Paste this in your console:
将此粘贴到您的控制台中:
var script = document.createElement('script');
script.onload = function() {
alert("Script loaded and ready");
};
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
From here: document.createElement("script") synchronously 从这里开始: document.createElement(“ script”)同步
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.