简体   繁体   中英

CloudFlare Detects that i'm using python selenium

I do not know how Cloudflare detects that I'm using python selenium. when I browse the website in my default browser, it works fine. I also researched StackOverflow but did not work any solution.

Here is the code.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_argument("--disable-dev-shm-usage")
options.add_argument('--no-sandbox')  
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36') 
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(ChromeDriverManager().install(),options=options)

I also tried:

from selenium import webdriver
from selenium_stealth import stealth

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(ChromeDriverManager().install(),options=options)

stealth(driver,
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win32",
        webgl_vendor="Intel Inc.",
        renderer="Intel Iris OpenGL Engine",
        fix_hairline=True,
        )

driver.get('https://www.merinfo.se/search?who=a&where')

What would be the changes needed that load website properly?

Can you try it just with beautifulsoup ?

import requests
from bs4 import BeautifulSoup


url = "https://www.merinfo.se/search?who=a&where"

soup = BeautifulSoup(requests.get(url).content, "html.parser")

for a in soup.select("h2"):
    print(a.text.strip())

Prints:

A Tam Tran
P-A Olsson
Carl A Karlsson
A Mui Bang
P A Pettersson
A Kieu Dan
A Buu Phung
A Luc Tran
M A Jony
A M Sundberg Reed
P-A Sköld
A Sat Voong
Hassan A Hayawi Hayawi
P-A Ingemar Pettersson
Elisabeth A-C Orrghen Paulsson
Kicki A E Freskgård
A-C Ingegerd Davidsson
P-A Per-Anders Jakobsson
P-A Sigurd Viking Lundkvist
Muna A A A Alqattan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM