试图从selenuim获取日期/平均值

时间:2020-10-01 11:49:53

标签: python-3.x selenium

使用Python 3.8,我需要从网站获取日期/年份和平均值并将其保存在Excel工作表下。 结构如下

  1. 2014年1月1日– 2015年1月1日2.1
  2. 2016年1月1日至2017年1月1日1.0
  3. 01/01/2018 – 01/01/2019 4.0

我想保存每个单元格下的所有日期/月份/年份,包括平均值 例子

  •  Cell 1              Cell 2 
    
  • 第1行2014年1月1日– 2015年1月1日2.1
  • 第1行2016年1月1日至2017年1月1日1.0

所以我按如下所示拉动Web元素

Dates_avg = driver.find_elements_by_xpath("//table[@class='performance']")

这将包含所有信息(日期/月/年和平均值)。 我正在尝试找到一种隔离它们的方法。 我尝试过日期时间,尝试像上面那样进行转换,所以可以在下面应用类似的内容

Dates_avg = str(driver.find_elements_by_xpath("//table[@class='performance']"))
data1_1 = dt.datetime.strptime(Dates_avg '"%d-%m-%Y"').date()

没有成功。任何帮助将大大增加 预先感谢

对延迟响应表示歉意。请为此查看HTML标签。 另外,我知道一旦导入此“ Dates_avg”,它就是一个列表。我试图弄清楚如何获取此列表并将其转换为日期/月/年并将其放在Excel中,以便我可以运行一些报告/统计信息 另请注意,此页面是动态加载的,因为没有静态链接

<tbody>
   <tr>
       <th scope="row">
                       <span class="performance">30/08/15</span> - <span class="performanceEnd">30/08/16</span>
       </th>
       <td class="value">11.22</td>
    </tr>
    <tr>
        <th scope="row">
                        <span class="performance">30/08/16</span> - <span class="performanceEnd">30/08/17</span>
        </th>
        <td class="value">10.12</td>
    </tr>
    <tr>
        <th scope="row">
                        <span class="performance">30/08/17</span> - <span class="performanceEnd">30/08/18</span>
        </th>
        <td class="value"> 5.16</td></tr>
    <tr>
        <th scope="row">
                        <span class="performance">30/08/18</span> - <span class="performanceEnd">30/08/19</span>
         </th>
         <td class="value">-0.64</td>
    </tr>
    <tr>
        <th scope="row">
                        <span class="performance">30/08/19</span> - <span class="performanceEnd">30/08/20</span>
    </th>
        <td class="value">-1.55</td>
    </tr>

0 个答案:

没有答案
相关问题