Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

python - Button clicked but nothing happens on webpage(Selenium WebDriver)

I am trying to click to "Get Data" button on this website. https://www1.nseindia.com/products/content/derivatives/currency/archieve_cd.htm

Here's my code. I have solved some of the issues but clicking doesnt work with no error.

import time
from selenium import webdriver

from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.common.action_chains import ActionChains

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By


chrome_options = Options()
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("user-data-dir=C:/Users/UserName/AppData/Local/Google/Chrome/User Data")
driver = webdriver.Chrome(ChromeDriverManager().install())

url = "https://www1.nseindia.com/products/content/derivatives/currency/archieve_cd.htm"
driver.get(url)
 
driver.find_element_by_xpath("//select[@name='h_filetype']/option[text()='Daily Bhavcopy']").click()
driver.find_element_by_id("date").send_keys('05-01-2021')
time.sleep(2)

driver.find_element_by_id("date").send_keys(Keys.ESCAPE)
time.sleep(2)

element = driver.find_element_by_css_selector('[class="getdata-button"]').click()

After clicking the button a zip file link should appear.Which has to be clicked next.

How to click "Get Data" button? Thank you very much :)

question from:https://stackoverflow.com/questions/65849774/button-clicked-but-nothing-happens-on-webpageselenium-webdriver

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
url = "https://www1.nseindia.com/archives/cd/bhav/CD_Bhavcopy050121.zip"
driver.get(url)

You delete all the rest of the code that exists after this.

driver.find_element_by_xpath("//select[@name='h_filetype']/option[text()='Daily Bhavcopy']").click()
driver.find_element_by_id("date").send_keys('05-01-2021')
time.sleep(2)

driver.find_element_by_id("date").send_keys(Keys.ESCAPE)
time.sleep(2)

element = driver.find_element_by_css_selector('[class="getdata-button"]').click()

This is the code that you don't need.

And if you want to make it to Auto Download more data try to make a code that will generate the calendar days and place them here CD_Bhavcopy050121.zip

So when you will want to extract the data from 05/01/2019 you will have to change the part of the html to this CD_Bhavcopy050119.zip


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...