selenium导入外部js文件并执行js问题

[scrapy] 2024-07-27 圈点776

摘要:selenium导入外部js文件并执行js问题

selenium导入外部js文件并执行js问题

示例:

hello.js

function hello(){

  document.body.innerHTML = "hello";

}


py中:

js="""

var s=document.createElement('script');

s.src='http://www.7160.com/js/uaredirect.js';

s.type = 'text/javascript';

document.head.appendChild(s)

"""

f.execute_script(js)

f.execute_script("hello()")

浏览器一般会提示:此文档中不允许的 <script> 来源 URI:“file:///D:/hello.js”

应该是跨域的问题。


selenium  

感谢反馈,已提交成功,审核后即会显示