我遇到了从需要登录的网站下载csv文件的问题。我已成功使用Selenium登录。但是,我不知道如何通过单击按钮下载csv文件。我试过检查,但我失败了。另外,网站上提供的csv文件没有复制网址。任何人都可以帮助我的代码。到目前为止,这是我写的。
fold
这是我检查csv文件按钮时得到的代码。
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.
答案 0 :(得分:0)
您可以使用以下xpath:
//tspan[text() = 'Download CSV']