假如我们要下载某个英文单词的百度翻译提供的语音,但是右键又捕获不到语音资源的超链接

F12调出浏览器控制台,分析资源的DOM特点

其中url对应的值为我们需要的语音资源,而且a标签的class值 op_dict3_how_read 是非常具有标识性的
所以可以通过下面的代码,利用js操作DOM的便利性获取url值
document.getElementsByClassName("op_dict3_how_read")[0].getAttribute('url')
下面为完整的js代码,加入了调用浏览器下载功能的代码,回车即可运行
function download(src) {
var $a = document.createElement('a');
$a.setAttribute("href", src);
$a.setAttribute("download", "");
var evObj = document.createEvent('MouseEvents');
evObj.initMouseEvent( 'click', true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);
$a.dispatchEvent(evObj);
};
var src = document.getElementsByClassName("op_dict3_how_read")[0].getAttribute('url');
download(src);

原创文章,作者:witersen,如若转载,请注明出处:https://www.witersen.com