A
A
authoraytee2021-08-09 00:55:27
Python
authoraytee, 2021-08-09 00:55:27

How to follow a link without getting access denied Python + Selenium?

I'm trying to follow a link using selenium + python but it gives me an "access denied" error, what should I do about it and how can I get around it?

Website: https://www.nseindia.com/

When you hover over Market Data, you need to click on Pre-Open Market

My code:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.action_chains import ActionChains
import time

options = Options()
driver = webdriver.Firefox(options=options)
driver.get("https://www.nseindia.com/") 

element_to_hover_over = driver.find_element_by_xpath("/html/body/header/nav/div[2]/div/div/ul/li[3]")
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()

time.sleep(2)

driver.find_element_by_xpath("//li/a[text()='Pre-Open Market']").click()


And the error:

Access Denied
You don't have permission to access " www.nseindia.com/market-data/pre-open-market-cm-an... " on this server.

Reference #18.6dfd733e.1628459288.e3c22b6

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RusiDev, 2021-08-10
@RusiDev

1. Use user-agent (google user-agent selenium).
2. Don't make requests often. If you want to test the program, then do it at least once every half a minute.
Most likely, the problem is in the user-agent, you need to turn your selenium into a "regular user".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question