简体   繁体   中英

How to open Microsoft Edge from a Script?

I've been doing a little python practice and lately noticed I can't seem to open Microsoft Edge from python2.7 using webbrowser when it is my default browser. It instead opens the tabs in IE. Is there a reason for this? Is there a workaround?

Here's some sample code:

import webbrowser as web
from random_words import RandomWords

def main():
    rw = RandomWords()

    for i in range(0, 30):
        word = rw.random_word()
        web.open(word, new=0)

main()

Use the MicrosoftWebDriver.exe downloaded from Microsoft WebDriver Downloads page , under 'Downloads' the current Release 14393, Version: 3.14393 | Edge version supported: 14.14393. Either place that driver executable in the same directory as the script, or point the webdriver.Edge to the path it's downloaded to. Then this should work as expected:

import os
from selenium import webdriver
import webbrowser as web
from random_words import RandomWords

# create new Edge session
dir = 'C:\Users\Me\Downloads' # use os.path.dirname(__file__) if same directory as script
edge_path = dir + "\MicrosoftWebDriver.exe"
driver = webdriver.Edge(edge_path)

def main():
    rw = RandomWords()

    for i in range(0, 30):
        word = rw.random_word()
        driver.get(word, new=0)

main()
#import (Program Directory to .exe Here) as web
from random_words import RandomWords

def main():
    rw = RandomWords()

    for i in range(0, 30):
        word = rw.random_word()
        web.open(word, new=0)

main()

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