【发布时间】:2018-10-16 09:39:45
【问题描述】:
我在尝试下载 csv 文件的地方有以下代码。
chromedriver = "/usr/lib/chromium-browser/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get('https://www.aemo.com.au/Electricity/National-Electricity-Market-NEM/Data-dashboard#aggregated-data')
time.sleep(5)
driver.find_element_by_xpath("//div[@class='dashboard-tab-content-options-state']//div[@class='dashboard-tab-content-options-item' and text()='SA']").click()
button = driver.find_element_by_xpath("//div[@class='dashboard-tab-content-download-btn' and text()= 'Download Historic Data as .csv']")
button.click()
html代码如下:-
<div id="dashADF" class="dashboard-tab-content" style="display: block;">
<div class="dashboard-tab-content-row">
<div class="dashboard-tab-content-options">
<div class="dashboard-tab-content-text-container">
<div class="dashboard-tab-content-title">Aggregated Price and Demand Data - Current Month</div>
</div>
<div class="dashboard-tab-content-options-state">
<div data-tabname="dashADF" data-current="true" class="dashboard-tab-content-options-item active">QLD</div>
<div data-tabname="dashADF" data-current="true" class="dashboard-tab-content-options-item">NSW</div>
<div data-tabname="dashADF" data-current="true" class="dashboard-tab-content-options-item">VIC</div>
<div data-tabname="dashADF" data-current="true" class="dashboard-tab-content-options-item">TAS</div>
<div data-tabname="dashADF" data-current="true" class="dashboard-tab-content-options-item">SA</div>
</div>
</div>
</div>
<div class="dashboard-tab-content-row">
<div class="dashboard-tab-content-download">
<div data-tabname="dashADF" data-current="true" class="dashboard-tab-content-download-btn">Download Current Month</div>
</div>
</div><hr>
<div class="dashboard-tab-content-row">
<div class="dashboard-tab-content-options">
<div class="dashboard-tab-content-text-container">
</div>
<div>
<div class="dashboard-tab-content-options-state">
<div data-tabname="dashADF" data-current="false" class="dashboard-tab-content-options-item active">QLD</div>
<div data-tabname="dashADF" data-current="false" class="dashboard-tab-content-options-item">NSW</div>
<div data-tabname="dashADF" data-current="false" class="dashboard-tab-content-options-item">VIC</div>
<div data-tabname="dashADF" data-current="false" class="dashboard-tab-content-options-item">TAS</div>
<div data-tabname="dashADF" data-current="false" class="dashboard-tab-content-options-item">SA</div>
</div>
<div class="dashboard-tab-content-options-time">
</div>
</div>
</div>
</div>
<div class="dashboard-tab-content-row">
<div class="dashboard-tab-content-download">
<div data-tabname="dashADF" data-current="false" class="dashboard-tab-content-download-btn">Download Historic Data as .csv</div>
</div>
</div>
</div>
【问题讨论】:
-
请提供您各自被检查元素的html代码
-
不要使用 text()='SA' 它有多个
-
@AshishKamble 你可以直接访问aemo.com.au/Electricity/National-Electricity-Market-NEM/…
标签: python-3.x selenium selenium-webdriver xpath webdriver