0

The first link was just a Selenium script for access to YouTube:

from selenium import webdriver

PATH = r"C:\Users\hp\Desktop\prog\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://youtube.com")

This Python program works perfectly fine, but when I try the same thing with a Cloudflare-protected website, it gets stuck in the wait page. I did some research and found an undetected Chrome driver to use, but I keep getting errors like "RuntimeError".

The libraries are all perfectly installed. I did more research and found a YouTube video that I could follow, but I’m still getting errors. Here is the second code:

import selenium
import undetected_chromedriver.v2 as uc
import time
options = uc.ChromeOptions()
py = "24.172.82.94:53281"
options.add_argument('--proxy-server=%s' % py)
driver = uc.Chrome(options=options)

driver.get("https://ifconfig.me/")
time.sleep(4)

The error I get:

AttributeError: 'ChromeOptions' object has no attribute 'add'

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

0

For something related to processes, which I cannot fully understand, you have to the lines driver = uc.Chrome() and driver.get('https://namecheap.com') in the if __name__ == '__main__':.

Also the link has to have the https:// or http:// for it to work.

Here's my working code:

import undetected_chromedriver as uc # The .v2 is not necessary in the last version of undetected_chromedriver
import time
def main():
    time.sleep(4)
    # Continue your code here

if __name__ == '__main__':
    driver = uc.Chrome()
    driver.get('https://namecheap.com')
    main()
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131