【发布时间】:2022-01-18 19:57:18
【问题描述】:
这是我的 Python 代码, 在重新加载 webdriver 时运行此代码后,我遇到错误 Access Denied You don't have permission to access site
我也尝试过无头方法,但也不起作用。
from time import sleep
import random
from selenium.webdriver.common.keys import Keys
import selenium
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
class StockData:
def __init__(self):
# chrome_options = Options()
# chrome_options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36')
# self.driver=webdriver.Chrome(executable_path=r'C:\Users\Arth\Desktop\codes\chromedriver.exe',chrome_options=chrome_options)
# agent = self.driver.execute_script("return navigator.userAgent")
options = Options()
options.headless = True
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36")
self.driver = webdriver.Firefox(profile,executable_path=r'C:\Users\Arth\Desktop\codes\geckodriver.exe')
def goSite(self):
driver=self.driver
driver.get("https://www.nseindia.com/market-data/volume-gainers-spurts")
sleep(3)
def start(self):
driver=self.driver
#driver.find_element_by_xpath("//img[contains(@title, 'Refresh') ]").click()
sleep(1)
names=driver.find_elements_by_xpath("//a[contains(@title, '_blank') ]")
print(names)
bot=StockData()
bot.goSite()
bot.start()```
【问题讨论】:
标签: javascript python selenium selenium-webdriver webdriver