通过Selenium和Python通过WebDriver实例调用execute_script()方法时,arguments [0]是什么? [英] What is arguments[0] while invoking execute_script() method through WebDriver instance through Selenium and Python?

查看:1804
本文介绍了通过Selenium和Python通过WebDriver实例调用execute_script()方法时,arguments [0]是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试爬网我感兴趣的页面.为此,我需要从HTML中删除element的属性.我要删除样式".所以我从Stackoverflow找到了一些代码.(我使用的是Chrome驱动程序)

I'm trying to crawl the pages that I interested in. For this, I need to remove attribute of element from HTML. 'style' is what I want to remove. So I find some codes from Stackoverflow.(i'm using Chrome for driver)

element = driver.find_element_by_xpath("//select[@class='m-tcol-c' and @id='searchBy']")
driver.execute_script("arguments[0].removeAttribute('style')", element)

参数[0] 在代码中起什么作用?谁能具体解释参数[0] 的角色?

What does arguments[0] do in the code? Can anyone explain arguments[0]'s roles concretely?

推荐答案

arguments是您要将从Python 传递到要执行的 JavaScript 的内容.

arguments is what you're passing from Python to JavaScript that you want to execute.

driver.execute_script("arguments[0].removeAttribute('style')", element) 

表示要用存储在element变量中的WebElement替换" arguments[0].

means that you want to "replace" arguments[0] with WebElement stored in element variable.

这与您在JavaScript中定义该元素相同:

This is the same as if you defined that element in JavaScript:

driver.execute_script("document.querySelector('select.m-tcol-c#searchBy').removeAttribute('style')")

您还可以将更多参数传递为

You can also pass more arguments as

driver.execute_script("arguments[0].removeAttribute(arguments[1])", element, "style")

这篇关于通过Selenium和Python通过WebDriver实例调用execute_script()方法时,arguments [0]是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆