简体   繁体   中英

downloading csv file button from a website

I am facing a problem of downloading a csv file from a website that requires login. I have successfully logged in using Selenium. However I don't know how to download the csv file by clicking on a button. I have tried to inspect but i Failed. plus there is no copy url of the csv file that is provided in the website. can anyone help me with the code. this is so far what I have written.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import NoSuchElementException
import time

chromedriver = "/webdrivers/chromedriver"
driver = webdriver.Chrome(chromedriver)

driver.get('https://user.sensogram.com/signin')   #driver.get(url)-- We get 
url by using driver which we initialy load.    
print ("Opened sensogram")
time.sleep(5)    #Just wait for sometime.
email = driver.find_element_by_xpath("//input[@name='usernameSignIn']") 
#Find email textaera.
email.send_keys('****')  #Send email to this text area. 
password = driver.find_element_by_xpath("//input[@name='passwordSignIn']") 
#Find password textarea.
password.send_keys('*******')   #send password to the password field.
button = driver.find_element_by_xpath("//button[@ng- 
click='submitted=true']")  #Find login button.
button.click()      #Click on login button. 

and this is the code I get when i inspect the csv file button.

<g class="highcharts-button highcharts-contextbutton highcharts-button-normal" style="cursor:pointer;vertical-align:center;font-size:12;font-weight:500;" stroke-linecap="round" transform="translate(399,8)"><title>Chart context menu</title><rect fill="rgba(0, 0, 0, 0.7)" class=" highcharts-button-box" x="0.5" y="0.5" width="100" height="32" rx="2" ry="2" stroke="none" stroke-width="1"></rect><text x="7" style="font-weight:normal;color:#fff;fill:#fff;" y="19"><tspan>Download CSV</tspan></text></g>

<rect fill="rgba(0, 0, 0, 0.7)" class=" highcharts-button-box" x="0.5" y="0.5" width="100" height="32" rx="2" ry="2" stroke="none" stroke-width="1"></rect>

<text x="7" style="font-weight:normal;color:#fff;fill:#fff;" y="19"> 
<tspan>Download CSV</tspan></text>

<tspan>Download CSV</tspan>

您可以使用以下xpath:

//tspan[text() = 'Download CSV']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM