使用Web驱动程序和Selenium访问网站被拒绝

ipakzgxi  于 2022-12-13  发布在  其他
关注(0)|答案(2)|浏览(176)

我有一个问题,即使是一个开放的网站使用“webdriver Chrome”。只有试图打开网站结束“拒绝访问”的信息,不知道为什么。下面是我的代码:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

import time

class PriceCheckPhoenix:
    def __init__(self):
        self.url_login = "https://www.phoenixcontact.com/online/portal/pl?1dmy&urile=wcm%3apath%3a/plpl/web/home"

        self.create_session()

    def create_session(self):
    # Run browser with webdriver

        driver = webdriver.Chrome(executable_path="D:/chromedriver_v84.exe")
        driver.get(self.url_login)

        time.sleep(2)

        # Find link to sub-website with login
        link = driver.find_element_by_xpath('//*[@id="pxc-funcnav"]/div[3]/ul/li[1]/a').get_attribute("href")
    
        driver.get(link)

        time.sleep(100)

代码描述:

1我创建浏览器chrome会话

2从self.url_login加载第一个网站

3已加载

4我需要找到网站上活动文本后面的链接才能登录

5我找到了它,并试图打开这个,但得到链接后的React是:

Access Denied
You don't have permission to access 
"http://www.phoenixcontact.com/online/portal/pl/pxc/offcontext/login/!ut/p/z1/tZJNa4NAEIZ_Sw45yszuuro9WkO1xqY2EqN7EbXGWPzYFDGlv74Gcio0oYTMZRgY3mcYHpAQg-yysa6yoe67rJnmRBqpu4zownzixDEYx2cWmIYTeYgrHSKQIFVRv0MieJZTZEITglFNLwTXRPaw03RGC6Qm10nOTttFN6hhD4lqVDPHY5nPcd-3JSQTy0ypQ5C4Onl5XUcmvgXCttzNWo-WCNuxLo-w6frPdjot_CfZxWsEciPhSjy7a7xN7xt_63M8kJdNmlSrPw4HaU2G9N1Qfg0Q_1Zke4JeiPHIeQH_KAshVE0a-GkQ24EPqm0F41WbLh5XWuKN3-fm78KgsmazH7dw0Ts!/dz/d5/L0lJSklKQ2dwUkEhIS9JRGpBQUF4QUFFUkNwcVlxLzRObEdRb1lwTWhUalVFZyEvWjZfR0FMNjE0ODI4RzNEQzBJMklPMlA2OTFHMDMvWjdfR0FMNjE0ODI4RzNEQzBJMklPMlA2OTFHSTcvdGFyZ2V0Vmlldy9sb2dpbg!!/" on this server.
Reference #18.d58655f.1597921471.5b29112

有人知道这里出了什么问题吗?:(当我尝试从正常的Chrome浏览器中的链接加载网站时,一切都很好:/谢谢大家的帮助。

nlejzf6q

nlejzf6q1#

请尝试下面的代码,让我知道它是否适合你:-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time

options = Options()
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.517 Safari/537.36'
options.add_argument('user-agent={0}'.format(user_agent))

driver = webdriver.Chrome(options=options)
wait = WebDriverWait(driver, 20)
action = ActionChains(driver)

driver.get("https://www.phoenixcontact.com/online/portal/pl?1dmy&urile=wcm%3apath%3a/plpl/web/home")
Login_Btn = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@class='pxc-fn-login']/a")))

action.move_to_element(Login_Btn).click().perform()

请注意-请在代码中进行相应的更改。

unguejic

unguejic2#

谷歌搜索把我带到这里。在尝试了几个选项。Undetected Chromedriver与一个非常简单的脚本没有任何选项为我工作。

import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get(<url here>)

相关问题