簡體   English   中英

使用帶有 Selenium 的 webdriver 拒絕訪問網站

[英]Access denied to website using webdriver with Selenium

即使是使用“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 session

#2 從 self.url_login 加載第一個網站

#3 已加載

#4 我需要在網站上的活動文本后面找到一個鏈接才能登錄

#5 我找到它並嘗試打開它,但得到鏈接后的響應是:

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 瀏覽器中的鏈接加載網站時,一切都很好:/ 謝謝大家的幫助。

請嘗試以下代碼,讓我知道它是否適合您:-

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()

注意 - 請相應地更改您的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM