首页 > 解决方案 > 硒获取价值python

问题描述

我是使用硒的新手,我想突出显示该行的这个值。当我使用 get 属性函数时,它会弹出一个错误。“TypeError: get_attribute() missing 1 required positional argument: 'name'”。我该如何解决它或缺少任何部分?

def HSI_realtimeprice():

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.hkex.com.hk/Products/Listed-Derivatives/Equity-Index/Hang-Seng-Index-(HSI)/Hang-Seng-Index-Options?sc_lang=zh-HK#&product=HSI')
hsi_price = driver.find_element_by_xpath('//div[@class="ls"]').get_attribute()
print(hsi_price)

HSI_realtimeprice()

在此处输入图像描述

标签: pythonselenium

解决方案


您应该输入您想要实现的属性。

hsi_price = driver.find_element_by_xpath('//div[@class="ls"]').get_attribute('insert_here')

看起来您想要获取文本,请使用innerHTML

driver.find_element_by_xpath('//div[@class="ls"]').get_attribute('innerHTML')

虽然这也可以通过以下方式实现.text

hsi_price = driver.find_element_by_xpath('//div[@class="ls"]').text

推荐阅读