Created
June 30, 2021 07:40
-
-
Save syakesaba/6c190ee30130f371b5bd62b7200ede07 to your computer and use it in GitHub Desktop.
chronium_edge_selenium_win.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
# Check MSEdge Version | |
# https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=c-sharp | |
# Donwload msedgedriver.exe and move it to C:\Windows\System32 | |
# https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ | |
# Donwload Cygwin and Python | |
# https://www.cygwin.com/ | |
# Donwload Selenium Tools | |
# pip install msedge-selenium-tools selenium | |
# Launch below as python script | |
import os | |
import json | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
from msedge.selenium_tools import Edge, EdgeOptions | |
def which(pgm): | |
path=os.getenv(r"PATH") | |
for p in path.split(os.path.pathsep): | |
p=os.path.join(p,pgm) | |
if os.path.exists(p) and os.access(p,os.X_OK): | |
return p | |
msedge_executable = which(r"msedge.exe") | |
local_appdata = os.environ["LOCALAPPDATA"] | |
msedge_userdata = local_appdata + r"\\Microsoft\Edge\\User Data" | |
OPTIONS = EdgeOptions() | |
OPTIONS.use_chromium = True | |
OPTIONS.binary_location = msedge_executable | |
#OPTIONS.add_argument("headless") | |
OPTIONS.add_argument(r"user-data-dir=%s" % msedge_userdata) | |
OPTIONS.add_argument(r"disable-gpu") | |
class SeleniumBrowser(Edge): | |
def __init__(self): | |
super().__init__(options=OPTIONS) | |
self.implicitly_wait(3) #sec | |
def __del__(self): | |
try: | |
self.quit() | |
except Exception as e: | |
print(e) | |
if __name__ == "__main__": | |
import atexit | |
import sys | |
import os | |
import code | |
sys.ps1 = '>> ' | |
import rlcompleter | |
rlcompleter.readline.parse_and_bind(r"tab: complete") | |
browser = SeleniumBrowser() | |
@atexit.register | |
def goodbye(): | |
try: | |
del browser | |
except UnboundLocalError as e: | |
pass | |
browser.get("http://www.yahoo.co.jp/") | |
code.interact(banner="browser....", local=locals()) | |
goodbye() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment