英文:
How to make python selenium less detectable?
问题
以下是您要翻译的内容:
"Okay, so I am making a bot for this website to automate account creation. I am using rotating ipv4 proxies and some other anti detection stuff but still being detected every time. Any ideas?
Here's how I'm initializing the driver and what options I'm using.
proxy = random.choice(proxys)
ua = UserAgent()
userAgent = ua.random
def main():
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=my chrome user data directory here')
options.add_argument(f'--proxy-server={proxy}')
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument(f'user-agent={userAgent}')
driver = uc.Chrome(service=Service(ChromeDriverManager(cache_valid_range=30).install()),options=options)
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
print(driver.execute_script("return navigator.userAgent;"))
sleep(1)
while True:
create_account(driver, catchall)
I also have tried chrome profiles, but I cannot make enough of those, and was wondering how I could implement those somehow. Because it seems after the website detects I am a bot, the chrome profile I was using no longer works.
I am being blocked out every time by the website, almost no matter what. Although sometimes it does happen to go through after I make some random changes. But I was expecting everything to be working now as almost everything that they can detect is being changed."
英文:
Okay, so I am making a bot for this website to automate account creation. I am using rotating ipv4 proxies and some other anti detection stuff but still being detected every time. Any ideas?
Here's how I'm initializing the driver and what options im using.
proxy = random.choice(proxys)
ua = UserAgent()
userAgent = ua.random
def main():
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=my chrome user data directory here')
options.add_argument(f'--proxy-server={proxy}')
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument(f'user-agent={userAgent}')
driver = uc.Chrome(service=Service(ChromeDriverManager(cache_valid_range=30).install()),options=options)
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
print(driver.execute_script("return navigator.userAgent;"))
sleep(1)
while True:
create_account(driver, catchall)
I also have tried chrome profiles, but I cannot make enough of those, and was wondering how I could implement those somehow. Because it seems after the website detects I am a bot, the chrome profile I was using no longer works.
I am being blocked out every time by the website, almost no matter what. Although sometimes it does happen to go through after I make some random changes. But I was expecting everything to be working now as almost everything that they can detect is being changed.
答案1
得分: 1
selenium-stealth
为了使 Python-Selenium 几乎不可检测,最好的选择是使用 selenium-stealth,它具有以下特点:
- 通过了所有公开的机器人测试。
- Selenium 可以用于登录 Google 帐户。
- 保持正常的 reCAPTCHA v3 分数
演示
- 代码块:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium_stealth import stealth
import time
options = Options()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
# Selenium Stealth 设置
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://bot.sannysoft.com")
time.sleep(5)
driver.save_screenshot("sannysoft.png")
driver.quit()
- 截图:
参考资料
您可以在以下地方找到一些相关的详细讨论:
英文:
selenium-stealth
To make Python-Selenium almost undetectable your best bet would be to use selenium-stealth which:
- Passes all public bot tests.
- Selenium can do google account login.
- Maintain a normal reCAPTCHA v3 score
A demonstration
-
Code Block:
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium_stealth import stealth import time options = Options() options.add_argument("start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option('useAutomationExtension', False) s = Service('C:\\BrowserDrivers\\chromedriver.exe') driver = webdriver.Chrome(service=s, options=options) # Selenium Stealth settings 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://bot.sannysoft.com") time.sleep(5) driver.save_screenshot("sannysoft.png") driver.quit()
-
Screenshot:
References
You can find a couple of relevant detailed discussions in:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论