python - 硒获取价值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()
解决方案
您应该输入您想要实现的属性。
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
推荐阅读
- paypal - 我可以使用智能按钮显示即时付款确认吗?
- excel - 从 Recordset 复制到动态创建的新工作簿中
- python - 基于多列选择数据框行,其中应创建新函数来处理某些列中的条件
- install4j - 在 Install4j8 中 - 当用户单击取消按钮时如何重定向到某个屏幕
- debugging - 如何在 ThisDocument_New() 中查看 Word 文档文本的变化
- android - 在viewfillper android的动态项上实现onclick
- javascript - 如何在 xslt 中使用 xpath 来导航 xhtml 文件?
- java - IntelliJ/Gradle:找不到方法“org.bouncycastle.crypto.CryptoServicesRegistrar.isInApprovedOnlyMode()Z”
- python - 为什么我无法访问 Python 模块?
- python - 使用 Sprite 组时更新类变量