单击nseindia.com上的“每月结算统计"的“获取数据"按钮不会使用Selenium和Python获取结果 [英] Clicking on Get Data button for Monthly Settlement Statistics on nseindia.com doesn't fetch results using Selenium and Python

查看:91
本文介绍了单击nseindia.com上的“每月结算统计"的“获取数据"按钮不会使用Selenium和Python获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从此处.

通过点击资本市场和2019-20年.我想单击获取数据.

By clicking on the capital market and 2019-20 year. I want to click on Get data.

我使用了以下代码:

driver = webdriver.Chrome(executable_path=chrome_path,options=chrome_options)

driver.get( nse_cash_keystats_page )


 driver.find_element_by_xpath( "//select[@id='h_filetype']/option[text()='Capital Market ']" ).click()

driver.find_element_by_xpath( "//select[@id='yearField']/option[text()='2019-2020']" ).click()

     downloadButton=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,'//input[@type="image"][@src="/common/images/btn-get-data.gif"]')))

driver.execute_script("arguments[0].click();", downloadButton)

通过使用上面的代码,我可以单击获取数据".但是它没有显示输出.

By using the above code, I am able to click on Get DATA. But it is not showing output.

请帮助我.谢谢.

推荐答案

我带您的代码进行了一些调整,并按如下所示进行了测试:

I took your code added a few tweaks and ran the test as follows:

  • 代码块:

  • Code Block:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www1.nseindia.com/products/content/equities/equities/eq_monthly_statistics.htm')
Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"select#h_filetype")))).select_by_visible_text("Capital Market ")
Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"select#yearField")))).select_by_visible_text("2019-2020")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.getdata-button#get[type='image'][src^='/common/images/btn-get-data.gif']"))).click()

类似于您的观察,我遇到了相同的障碍,但没有得到如下结果:

Similar to your observation, I have hit the same roadblock with no results as follows:

似乎元素上的click()确实显示为获取数据.但是在检查网页 DOM树时,您会发现其中一些<script>标签是指具有关键字 akam JavaScripts .例如:

It seems the click() on the element with text as Get Data does happens. But while inspecting the DOM Tree of the webpage you will find that some of the <script> tag refers to JavaScripts having keyword akam. As an example:

  • <script type="text/javascript" src="https://www1.nseindia.com/akam/11/52349752" defer=""></script>
  • <noscript><img src="https://www1.nseindia.com/akam/11/pixel_52349752?a=dD01ZDZiMTA5OGQ0MDljYTYxN2RjMjc3MzBlN2YwMDQ0NjlkZDNiNTMzJmpzPW9mZg==" style="visibility: hidden; position: absolute; left: -999px; top: -999px;" /></noscript>
  • <script type="text/javascript" src="https://www1.nseindia.com/akam/11/52349752" defer=""></script>
  • <noscript><img src="https://www1.nseindia.com/akam/11/pixel_52349752?a=dD01ZDZiMTA5OGQ0MDljYTYxN2RjMjc3MzBlN2YwMDQ0NjlkZDNiNTMzJmpzPW9mZg==" style="visibility: hidden; position: absolute; left: -999px; top: -999px;" /></noscript>

这清楚表明该网站受 Bot Manager > Akamai 提供的高级漫游器检测服务> ,并且响应被阻止.

Which is a clear indication that the website is protected by Bot Manager an advanced bot detection service provided by Akamai and the response gets blocked.

根据文章 Bot Manager-基础:

因此可以得出结论,检测到对数据的请求是由 WebDriver 实例,响应被阻止.

So it can be concluded that the request for the data is detected as being performed by Selenium driven WebDriver instance and the response is blocked.

一些文档:

  • Bot Manager
  • Bot Manager : Foundations

一些相关的讨论:

  • Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection
  • Unable to use Selenium to automate Chase site login

这篇关于单击nseindia.com上的“每月结算统计"的“获取数据"按钮不会使用Selenium和Python获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆