【发布时间】:2020-10-27 18:44:03
【问题描述】:
''' 尝试从 NSE 获取 Equity Derivatives 数据 https://www.nseindia.com/->Market 数据-> 衍生品市场 一直有效,直到点击操作,浏览器导航到衍生品市场,但随后访问 拒绝错误如下
<h1>
Access Denied
</h1>
You don't have permission to access "http://www.nseindia.com/market-data/equity-derivatives-watch" on this server.
<p>
Reference #18.386dcc17.1603823463.54b06d7
</p>
'''
from selenium import webdriver
from selenium.webdriver import ActionChains
from bs4 import BeautifulSoup
import time
# Tried all possible options below
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://www.nseindia.com/")
marketdata = driver.find_element_by_xpath("//*[@id='main_navbar']/ul/li[3]/a")
derivativesmarket = driver.find_element_by_xpath("//*[@id='main_navbar']/ul/li[3]/div/div[1]/div/div[1]/ul/li[3]/a")
actions = ActionChains(driver)
actions.move_to_element(marketdata).move_to_element(derivativesmarket).click().perform()
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
# soup = BeautifulSoup(html,'lxml')
time.sleep(7)
print(soup.prettify())[enter image description here][1]
【问题讨论】:
-
服务器本身给你的访问权限是否被拒绝?
标签: python selenium selenium-chromedriver http-status-code-403