简体   繁体   English

使用Python运行网站的javascript函数

[英]Run a javascript function of a website using Python

I've been wondering whether or not this is possible - 我一直在想这是否可能-

Here is a picture of Chrome's "inspect element" on this website. 这是此网站上Chrome的“检查元素”的图片。 在此处输入图片说明

Is it possible for me to run the "goCourseDetails" js function with my own parameters? 我可以使用自己的参数运行“ goCourseDetails” js函数吗?

I'm using Python and selenium to try and write a script that does that for me, but I don't know how to access the JS function. 我正在使用Python和Selenium尝试编写一个脚本来为我完成任务,但是我不知道如何访问JS函数。

Thanks in advance. 提前致谢。

You can use driver.execute_script() to execute javascript snippet in browser. 您可以使用driver.execute_script()在浏览器中执行javascript代码段。

The function goCourseDetails can be obtain from browser global variable window 可以从浏览器全局变量window获取功能goCourseDetails

driver.execute_script('window.goCourseDetails.call(null, arguments)',
      <department>, <degreelevel>, <course>, <detail>, <year>, <semester>
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以使用网站的网址在网站上运行javascript函数? - is it possible to run a javascript function on a website by using the url of the website? Javascript/Python - 单击网站上的按钮并在 python 中运行 function - Javascript/Python - click a button on a website and run a function in python 是否可以打开一个网站,然后使用 Python 在其中运行 JavaScript? - Would it be possible to open a website and then run JavaScript in it using Python? 如何使用 python 运行特定的 Javascript 函数 - How to run a specific Javascript function using python 使用 python 抓取 javascript 网站和脚本标签 - Scraping javascript website and script tags using python 使用 Python 使用 JavaScript 表单自动登录网站 - Using Python to Automatically Login to a Website with a JavaScript Form 弹出窗口中的.NET MVC 4网站javascript功能无法运行 - .NET MVC 4 website javascript function in popup window wouldn't run 有没有办法从网站的源代码以编程方式运行 javascript function - Is there a way to programmatically run a javascript function from the source of a website 在网站上运行JavaScript命令 - Run JavaScript command on website Python 用两个参数运行 JavaScript 函数 - Python to run JavaScript function with two parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM