1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| from pathlib import Path
import sys
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
#from selenium.webdriver.support.ui import Select
# from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
CONTENT = """<html>
<div id="statistiques_6451_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer"><div class="row btable-row1"><div id="btable_statistiques_6451_caption" class="col-sm-8"></div><div id="btable_statistiques_6451_length" class="col-sm-4"></div></div><div class="row btable-row2"><div id="btable_statistiques_6451_filter" class="col-sm-6"><div id="statistiques_6451_filter" class="dataTables_filter" style="float: left;"><label>Rechercher :<input type="search" class="form-control input-sm" placeholder="" aria-controls="statistiques_6451" style="margin: 0px 10px 0px 0px; background-color: rgb(255, 255, 255); border-color: rgb(204, 204, 204); border-width: 1px;"></label></div><div class="dt-buttons btn-group"></div><div class="btn-group" id="statistiques_6451_btn_export" role="group"><button title="Exporter le tableau" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">Export</button><div id="statistiques_6451_export" class="dropdown-menu dropdown-export"><a class="btn btn-default buttons-csv buttons-html5 btn-sm btn-export-format" tabindex="0" aria-controls="statistiques_6451" href="#"><span><i class="fa fa-file-text-o" aria-hidden="true" style="font-size:16px"></i> CSV</span></a><a class="btn btn-default buttons-excel buttons-html5 btn-sm btn-export-format" tabindex="0" aria-controls="statistiques_6451" href="#"><span><i class="fa fa-file-excel-o" aria-hidden="true" style="font-size:16px"></i> Excel</span></a><a class="btn btn-default buttons-print btn-sm btn-export-format" tabindex="0" aria-controls="statistiques_6451" href="#"><span><i class="fa fa-print" aria-hidden="true" style="font-size:16px"></i> Impression</span></a></div></div><button title="Reinitialiser le tableau" class="btn btn-default btn-sm" id="statistiques_6451_btn_reinitialiser"><span class="glyphicon glyphicon-repeat"></span> Reinitialiser</button></div><div id="btable_statistiques_6451_pagination" class="col-sm-6"></div></div><div class="row btable-row3"><div id="btable_statistiques_6451_table" class="col-sm-12"><table class="btable table table-bordered table-condensed table-striped table-hover no-footer dataTable" id="statistiques_6451" data-table-pagination="false" data-table-export="true" data-table-page-info="false" data-table-fixheader="false" data-table-export-nom="Total des types de bac actuels par voeux" data-table-export-format="csv,excel,print" role="grid" style="visibility: visible;">
<thead>
</thead>
<tbody>
<tr class="odd" role="row">
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
</tr><tr class="even" role="row">
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
</tr><tr class="odd" role="row">
<td class=" text-left">6</td>
<td class=" text-left">0</td>
<td class=" text-left">6</td>
<td class=" text-left">0</td>
<td class=" text-left">6</td>
</tr><tr class="even" role="row">
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
</tr><tr class="odd" role="row">
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
</tr></tbody>
</table><div id="statistiques_6451_processing" class="dataTables_processing panel panel-default" style="display: none;">Traitement en cours...</div></div></div><div class="row btable-row4"><div id="btable_statistiques_6451_info" class="col-sm-5"></div><div id="btable_statistiques_6451_pagination_bottom" class="col-sm-7"></div></div></div>
<br>
<h2 class="mt-1 mb-1 ml-1">équivalents</h2>
<div id="statistiques2_6451_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer"><div class="row btable-row1"><div id="btable_statistiques2_6451_caption" class="col-sm-8"></div><div id="btable_statistiques2_6451_length" class="col-sm-4"></div></div><div class="row btable-row2"><div id="btable_statistiques2_6451_filter" class="col-sm-6"><div id="statistiques2_6451_filter" class="dataTables_filter" style="float: left;"><label>Rechercher :<input type="search" class="form-control input-sm" placeholder="" aria-controls="statistiques2_6451" style="margin: 0px 10px 0px 0px; background-color: rgb(255, 255, 255); border-color: rgb(204, 204, 204); border-width: 1px;"></label></div><div class="dt-buttons btn-group"></div><div class="btn-group" id="statistiques2_6451_btn_export" role="group"><button title="Exporter le tableau" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">Export</button><div id="statistiques2_6451_export" class="dropdown-menu dropdown-export"><a class="btn btn-default buttons-csv buttons-html5 btn-sm btn-export-format" tabindex="0" aria-controls="statistiques2_6451" href="#"><span><i class="fa fa-file-text-o" aria-hidden="true" style="font-size:16px"></i> CSV</span></a><a class="btn btn-default buttons-excel buttons-html5 btn-sm btn-export-format" tabindex="0" aria-controls="statistiques2_6451" href="#"><span><i class="fa fa-file-excel-o" aria-hidden="true" style="font-size:16px"></i> Excel</span></a><a class="btn btn-default buttons-print btn-sm btn-export-format" tabindex="0" aria-controls="statistiques2_6451" href="#"><span><i class="fa fa-print" aria-hidden="true" style="font-size:16px"></i> Impression</span></a></div></div><button title="Reinitialiser le tableau" class="btn btn-default btn-sm" id="statistiques2_6451_btn_reinitialiser"><span class="glyphicon glyphicon-repeat"></span> Reinitialiser</button></div><div id="btable_statistiques2_6451_pagination" class="col-sm-6"></div></div><div class="row btable-row3"><div id="btable_statistiques2_6451_table" class="col-sm-12"><table class="btable table table-bordered table-condensed table-striped table-hover no-footer dataTable" id="statistiques2_6451" data-table-pagination="false" data-table-export="true" data-table-page-info="false" data-table-fixheader="false" data-table-export-nom="Total des types de bac par voeux" data-table-export-format="csv,excel,print" style="visibility: visible;" role="grid">
<thead>
</thead>
<tbody>
<tr role="row" class="odd">
<td class=" text-left">11</td>
<td class=" text-left">2</td>
<td class=" text-left">9</td>
<td class=" text-left">6</td>
<td class=" text-left">5</td>
</tr><tr role="row" class="even">
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
<td class=" text-left">0</td>
<td class=" text-left">1</td>
</tr></tbody>
</table><div id="statistiques2_6451_processing" class="dataTables_processing panel panel-default" style="display: none;">Traitement en cours...</div></div></div><div class="row btable-row4"><div id="btable_statistiques2_6451_info" class="col-sm-5"></div><div id="btable_statistiques2_6451_pagination_bottom" class="col-sm-7"></div></div></div>
<br>
<div id="bouton">
<table class="bouton">
<tbody><tr>
<td class="gauche"></td>
<td class="milieu"><a href="statistiques?ACTION=1" class="bouton">Retour</a> </td>
<td class="droite"></td>
</tr></tbody></table>
</div>
</html>
"""
FILE_ = Path.home() / "toto.html"
FILE_.write_text(CONTENT)
print(FILE_)
try:
driver.get(f"file://{FILE_}")
print(driver.page_source)
for tag in driver.find_elements(By.XPATH, "//table[@id='statistiques_6451']/tbody/tr"):
print("statistiques_6451", tag, tag.text)
for tag in driver.find_elements(By.XPATH, "//table[@id='statistiques2_6451']/tbody/tr"):
print("statistiques2_6451", tag, tag.text)
print("-"*12)
print("Autre façon de parcourir...")
for id in ("statistiques_6451", "statistiques2_6451"):
for tag in driver.find_elements(By.CSS_SELECTOR, f"table#{id} tr"):
print(id, tag, tag.text)
finally:
driver.quit() |
Partager