pythonselenium-webdriverweb-scraping

How to get through human verification while web scraping?


I am trying to write a web scraping code in Python, but after logging in to a website, its access to it is always denied due to human verification.

I used the code below and the website says the following:

"Access to this page has been denied because we believe you are using automation tools to browse the website.This may happen as a result of the following:

Javascript is disabled or blocked by an extension (ad blockers for example)

Your browser does not support cookies

Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking them from loading."

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

def login(login_page, my_username, my_password):
    user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"

    options = webdriver.EdgeOptions()
    options.add_argument(f"user-agent={user_agent}")
    options.add_argument("--enable-javascript")

    driver = webdriver.Edge(options=options)
    driver.set_window_size(1080, 800)
    driver.get(login_page)

    driver.find_element(By.ID, "username").send_keys(my_username) 
    driver.find_element(By.ID, 'loginbutton').click()

    time.sleep(1)

    driver.find_element(By.ID, "password").send_keys(my_password) 
    driver.find_element(By.ID, 'loginbutton').click()

    return(driver)

Solution

  • hi first what webside you trying to scrape ?

    *** try to use ---> https://pypi.org/project/undetected-chromedriver/ *** but it only works for chrome *** also you can try to intercept the request or exe js is less likely to raise cdp detection flag