3

I have a problem with even an open website using "webdriver Chrome". Only trying to open the website end with "Access denied" information and don't know why. Below is my code:

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)

Description to code:

#1 I create browser chrome session

#2 Loading first website from self.url_login

#3 Is loaded

#4 I need to find a link behind the active text on the website to log in

#5 I found it and try to open this, but the response after getting a link is:

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

Is anyone know what is wrong here? :( When I try to load the website from the link in normal Chrome browser it's all fine :/ Thank you all for any help.

Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
ArturY
  • 47
  • 1
  • 7

2 Answers2

8

Please try the below code and let me know if it works for you :-

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

Note - Please make the changes in your code accordingly.

Swaroop Humane
  • 1,770
  • 1
  • 7
  • 17
  • Hey, thank you for answer, Yes this is work fine I see. I understand that behind this "button" is something more, some script and not only this URL possible to get and open? :( Diffrent between my and your code is this, You use something like "mouse click"? Script try to find object on website and just click like mouse but without move cursor? But thank you for answer, working fine :o :) – ArturY Aug 21 '20 at 11:32
0

Google search brought me here. After trying several options. Undetected Chromedriver with a very simple script without any options worked for me.

import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get(<url here>)
William
  • 464
  • 2
  • 16