我一直在尝试为“投手”选择过滤器,然后从此处下载到Excel:https://www.rotowire.com/baseball/stats.php
我尝试了以下操作,但遇到错误/不确定如何选择必要的项目
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://www.rotowire.com/baseball/stats.php")
elem = driver.find_elements_by_xpath("//div[contains(@class,'filter-tab is-selected')]")
理想情况下(目前),该脚本在本地运行并下载文件。
答案 0 :(得分:0)
这将下载投手数据。网站上似乎存在某种类型的隐藏html。这就是为什么代码首先找到整个表,然后再找到excel按钮的原因。
<nav id="sidebar">
<ul class="list-unstyled components">
<li class="active">
<a href="#toolboxSubMenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">Toolbox</a>
<ul class="collapse list-unstyled" id="toolboxSubMenu">
<li>
<a asp-area="" asp-page="/Toolbox/UserManagement/List">User</a>
</li>
<li>
<a asp-area="" asp-page="/Toolbox/UserManagement/List">Activity</a>
</li>
<li>
<a asp-area="" asp-page="/Toolbox/DataCallManagement/List">Data Call Management</a>
</li>
<li>
<a href="#formSubMenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle">Form</a>
<ul class="collapse list-unstyled" id="formSubMenu">
<li class="leveltwo">
<a asp-area="" asp-page="/Toolbox/SectionManagement/List">Section</a>
</li>
<li class="leveltwo">
<a asp-area="" asp-page="/Toolbox/QuestionManagement/List">Question</a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a asp-area="" asp-page="/Index">Dashboard</a>
</li>
<li>
<a asp-area="" asp-page="#">Help</a>
</li>
</ul>
</nav>