Getting '403 Forbidden' error when using headless chrome with python selenium

jcoder

When using regualr chromedriver, my tests run without any issues and I get the test results. When I am trying to launch headless chrome with python and selenium, I get a '403 Forbidden' error on the screenshot and selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: on the console. I passed all these arguments and still get the same result :

chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1920,1080')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--allow-running-insecure-content')
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=chrome_options)

I also tried the from fake_headers import Headers but the issue still persists

Antoniojbueno
#!/usr/bin/python3
#try this 
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time,os
from bs4 import BeautifulSoup
from pyvirtualdisplay import Display
from fake_useragent import UserAgent
def web(url):
    display = Display(visible=0, size=(1920, 1080)) 
    display.start()
    ua = UserAgent()
    userAgent = ua.chrome
    chrome_options = Options()
    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    chrome_options.add_experimental_option('useAutomationExtension', False)
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
    chrome_options.add_argument(f'user-agent={userAgent}')
    driver = webdriver.Chrome (options = chrome_options)
    driver.get(url)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

getting 403 forbidden error

HTTP Error 403: Forbidden when using NLTK

Why am I be getting a 403 Forbidden error when using @csrf_exempt in AJAX request?

Web Scraping getting error (HTTP Error 403: Forbidden) using urllib

Error on Selenium data dir when using headless

Getting 403 Forbidden error when requesting JSON output with apikey

Microsoft Graph API : "403 forbidden" error when getting groups conversations

Getting 403 Forbidden error message when trying to access a cusotm route

Getting 403 Forbidden when using Google Photos API

Getting error 403 when attempting to webscrape using python and jupyter notebook

Selenium in Java is not finding element when using headless Chrome

403 forbidden error when using Spring boot - security

403 Forbidden when using Cheerio

python cookielib error:403 Forbidden

How do you run headless chrome and a proxy using selenium in python?

TimeoutException using Google Chrome in headless mode through Python Selenium

Python Selenium causing error when screenshotting when running headless

Getting 403 (Forbidden) when trying to use CORS

Getting a 403 Forbidden when going to a URL with PhantomJS

Getting 403 Forbidden while using gate facade

Why am I getting a 403 (Forbidden) error when I make a second Rest API call?

Getting 403 (Forbidden) error when accessing static site from custom domain

Why am I getting botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden?

TapKey - Getting a 403 forbidden error when trying to view own locks via the API

Getting a 403 Forbidden error when attempting to publish to GCP from a Spring Boot application

HTTP Error 403: Forbidden when reading HTML

403 Forbidden Error when attempting to authenticate

403 Forbidden error when accessing site (Joomla)

403 forbidden error while getting indexes from AWS Elastic search using AWS SDK