Emulate and Automate Chrome using Profiles and Selenium
Project description
Selenium-Profiles
- Overwrite device metrics using Selenium
- Mobile and Desktop emulation
- Undetected by Google, Cloudflare, ..
- Modifying headers supported using Selenium-Interceptor
- Touch Actions
Feel free to test my code!
Getting Started
Dependencies
- Python >= 3.7
- Windows or Google-Colab (Linux not tested yet)
- Chrome-Browser installed
- selenium-profiles
Installing
- [Windows] Install Chrome-Browser
pip install selenium-profiles
Start Driver
from selenium_profiles.driver import driver as mydriver
from selenium_profiles.profiles import profiles
from selenium.webdriver.common.by import By # locate elements
mydriver = mydriver()
driver = mydriver.start(profiles.Windows(), uc_driver=False) # or .Android
# get url
driver.get('https://browserleaks.com/client-hints') # test client hints
input("Press ENTER to exit: ")
driver.quit() # Execute on the End!
Don't forget to execute
driver.quit()
in the End. Else-wise your temporary folder will get flooded! (Windows)
Run with Google-Colab
Google-Colab (file: google-colab/selenium_profiles.ipynb)
Profiles
Example Profile:
{
"options": {
"browser": {
"sandbox": true,
"window_size": {"x":1024,"y":648},
"headless": false,
"load_images": true,
"incognito": true,
"app": false,
"gpu": false,
"proxy": null,
"proxy_method": null
},
"extensions": {"extension_paths": []},
"option_args": ["--my-arg1", "..."],
"capabilities": [],
"adb": false,
"adb_package": "com.android.chrome",
"use_running_app": true
},
"cdp": {
"browser": {
"pointer_as_touch": false,
"darkmode": false,
"mobile": true
},
"touch": true,
"maxtouchpoints": 5,
"cdp_args": [],
"emulation": {"mobile":true,"width": 384, "height": 700, "deviceScaleFactor": 10,
"screenOrientation": {"type": "portrait-primary", "angle": 0}},
"useragent": {
"platform": "Linux aarch64",
"userAgent": "Mozilla/5.0 (Linux; Android 11; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Mobile Safari/537.36",
"userAgentMetadata": {
"brands": [{"brand": "Google Chrome", "version": "105"}, {"brand": "Not)A;Brand", "version": "8"},
{"brand": "Chromium", "version": "105"}],
"fullVersionList": [{"brand": "Google Chrome", "version": "105.0.5195.136"},
{"brand": "Not)A;Brand", "version": "8.0.0.0"},
{"brand": "Chromium", "version": "105.0.5195.136"}],
"fullVersion": "105.0.5195.136",
"platform": "Android",
"platformVersion": "11.0.0",
"architecture": "",
"model": "HD1913",
"mobile": true,
"bitness": "",
"wow64": false}
}}
}
Modify-headers
from selenium_interceptor.interceptor import cdp_listener
from selenium_profiles import driver as mydriver
from selenium_profiles.profiles import profiles
mydriver = mydriver()
profile = profiles.Windows()
driver = mydriver.start(profile)
cdp_listener = cdp_listener(driver=driver)
cdp_listener.specify_headers({"sec-ch-ua-platform":"Android"})
thread = cdp_listener.start_threaded(listener={"listener": cdp_listener.requests, "at_event": cdp_listener.modify_headers})
driver.get("https://modheader.com/headers?product=ModHeader")
Don't forget to execute
cdp_listener.terminate_all()
Touch_actions
Example demonstration script
from selenium_profiles.driver import driver as mydriver
from selenium_profiles.profiles import profiles
from selenium_profiles.scripts.touch_actions import touch_action_chain, mid_location
from selenium.webdriver.common.by import By
# Start Driver
mydriver = mydriver()
profile = profiles.Android()
driver = mydriver.start(profile, uc_driver=False) # or .Android
# initialise touch_actions
touch_actions = touch_action_chain(driver)
driver.get("https://cps-check.com/de/multi-touch-test")
touch_box = driver.find_element(By.XPATH,'//*[@id="box"]') # Get element
location = mid_location(touch_box) # get element middle location
# setup actions
touch_actions.pointer_action.move_to_location(location['x'],location['y'])
touch_actions.pointer_action.pointer_down()
# perform actions
touch_actions.perform()
# now you should see a touch indication point on the Website
# quit driver
input('Press ENTER to quit Driver\n')
driver.quit()
To export a profile:
go to https://js.do/kaliiiiiiiiiii/get_profile in your browser and copy the text.
Help
Please feel free to open an issue or fork!
Known Bugs
Todo
- installer.py script
- chromedriver
- Windows
- Jupyter (Google-Colab)
- Linux (not tested yet!)
- Chrome-Browser
- chromedriver
- implement headless javascript headless
- Mobile emulation
- click_as touch makes code hung
- default metrics
- Android
- Windows
- IOS
- Linux
- Tablet
- test.py script
- test_driver.py
- useragent, profile_export (no error)
- Windows
- Android
- useragent, profile_export (no error)
- test_driver.py
- audio_captcha_solver
- support for
- Windows
- Jupyter Notebook (Google-Colab)
- Linux
Deprecated
- Stealth method (Detected by Google)
- Selenium-Wire (proxy, no https)
- buster captcha solver | wontfix
- Undetected-Chromedriver (Selenium-Webdriver should be used directly)
- Modheader-Selenium (Changing headers now possible without)
- selenium-wire (Changing headers now possible without)
Authors
License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Disclaimer
I am not responsible what you use the code for!!! Also no warranty!
Acknowledgments
Inspiration, code snippets, etc.
- Selenium
- selenium-documentation
- README-Template
- headless_js
- Selenium-Stealth
- Undetected-Chromedriver
- Selenium-Wire
- Modheader-Selenium
- ModHeader docs
- buster captcha solver | wontfix
- audio_captcha_solver
- Chromedriver-Options List
- Chrome DevTools Protocol (cdp_cmd)
- example_pypi_package
- google-colab installer
- scripts/touch_action_chain
- cdp_event_listeners
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for selenium_profiles-2.2.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9d850ab3a84d3c86e9cb551d52df8a81cf3f0c25dc6f8cf5d6bd15d0bef0bc1 |
|
MD5 | ddcdbdf462b23909bc862e35854cf209 |
|
BLAKE2b-256 | 56e09f9746635164879cd285063919233cf9e945c3a345ee4ed7deeeff07f8c3 |