如果你看一下页面的源代码,你会明白,几乎所有的
SELECt,
DIV都是元素
faked和从Javascript创建的,这就是为什么webdriver的不能
查阅 它们。
但是,有一种解决方法,方法是使用
ActionChains打开您的开发人员控制台,然后在所需元素上注入 人工 CLICK,实际上是
Label 触发了 NBA 数据加载…这是一个工作示例:
from selenium import webdriverfrom selenium.webdriver.common import action_chains, keysimport timedriver = webdriver.Firefox()driver.get('Your URL here...')assert 'NBA' in driver.page_sourceaction = action_chains.ActionChains(driver)# open up the developer console, mine on MAC, yours may be diff key comboaction.send_keys(keys.Keys.COMMAND+keys.Keys.ALT+'i')action.perform()time.sleep(3)# this below ENTER is to rid of the above "i"action.send_keys(keys.Keys.ENTER)# inject the Javascript...action.send_keys("document.querySelectorAll('label.boxed')[1].click()"+keys.Keys.ENTER)action.perform()另外,要替换所有
ActionChains命令,您可以
execute_script像这样简单地运行:
driver.execute_script("document.querySelectorAll('label.boxed')[1].click()")无论如何,至少您可以在我的本地文件上找到所需的地方…希望对您有所帮助!



