【发布时间】:2020-02-25 21:29:05
【问题描述】:
尝试选择其他财务报表(默认为损益表),以及在第二个年度/季度列表之间切换。我可以缩小范围以获取列表的属性,但我无法与列表交互。
import time
import urllib.request
from bs4 import BeautifulSoup
from selenium import webdriver
symbol = 'bmo'
driver = webdriver.Chrome()
driver.get('https://web.tmxmoney.com/financials.php?qm_symbol={}'.format(symbol))
time.sleep(2)
dropdown = driver.find_elements_by_css_selector('a.qmod-dropdown_toggle.qmod-type-toggle + ul.qmod-dropdown-menu > li > a')
for option in dropdown:
if option.get_attribute('innerText') == 'Balance Sheet':
option.send_keys('Balance Sheet')
【问题讨论】:
-
我无法使用相同的方法。 .click() 不起作用,并且没有“选择”类。我确实注意到在 标记内,当前显示的选项的类值将具有“qmod-active”的值,当我选择另一个选项时,取消选择的选项的类将是“”和新选择的将采用“qmod-active”的值,但我不知道如何更改它(这很新)。
-
我能够使用以下方法更改“资产负债表”的类别,但选择仍停留在损益表的原始默认值中。 driver.execute_script("arguments[0].setAttribute('class','qmod-active')", option)
标签: python selenium-webdriver iframe drop-down-menu webdriverwait