【问题标题】:selenium: bypass access denied硒:绕过访问被拒绝
【发布时间】:2020-08-08 12:06:48
【问题描述】:

我正在尝试使用 Selenium 浏览网站,但出现错误:拒绝访问。您无权访问此服务器上的“http://tokopedia.com/”。

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options

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




CHROMEDRIVER_PATH = r'C:/chromedriver.exe'
tokopedia = "https://tokopedia.com/"

options = Options()
options.add_argument("--headless")
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)



driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=options)
driver.get(tokopedia)

print(driver.page_source)

如何解决?感谢您的帮助

【问题讨论】:

    标签: python-3.x selenium selenium-chromedriver


    【解决方案1】:

    试试下面的代码。它对我有用 -

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    tokopedia = "https://tokopedia.com/"
    
    options = Options()
    options.add_argument("--headless")
    options.add_argument('--disable-gpu')
    options.add_argument('--no-sandbox')
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    
    user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'
    options.add_argument('user-agent={0}'.format(user_agent))
    
    driver = webdriver.Chrome(options=options)
    driver.get(tokopedia)
    
    print(driver.page_source)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-10
      • 2021-03-06
      • 2011-05-15
      • 2010-09-06
      • 2014-03-22
      • 2013-08-10
      • 2018-04-20
      相关资源
      最近更新 更多