【发布时间】:2021-05-17 10:14:34
【问题描述】:
我想将网站的 css 从 python 更改为 selenium。
到目前为止,我所做的就是获取 CSS 的价值。
我想改变这个 css 的值。
下面Python代码运行结果:0px 0px 0px 270px
从 0px 0px 0px 270px 怎么改成0px 0px 0px 0px?
这些方法我都试过了,但最后并不是都成功了。
driver.execute_script("arguments[0].style.margin = '0px 0px 0px 0px';") driver.execute_script("arguments[0].setAttribute('class','0 0 0 0px')", 元素) driver.execute_script("/html/body/div1/div[3]/div[3].setAttribute('style','0px 0px 0px 0px;');",element)
from selenium import webdriver
#load
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
# option
webdriver_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=webdriver_options, executable_path = r'chromedriver.exe')
url = 'https://www.mql5.com/en/code/29526'
driver.get(url)
element = driver.find_element_by_class_name("code-content").value_of_css_property("margin")
print(element)
sleep(3333333)
【问题讨论】:
-
codebase...css文件是动态生成的吗?
-
您能分享一下您想这样做的原因吗?
标签: javascript python html css selenium