selenium调用不了Microsoft Egde浏览器
新手一枚,想写个爬虫,结果调用浏览器就直接报错了WebDriverException: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687
在网上百度了,也下了Egde的驱动,放到了浏览器的Application目录下,anaconda的scripts目录下也放了,环境变量path也新添了这两条路径,为什么还是报错{:9_218:} {:9_218:}
球球哪位大佬能救救我这只小菜鸟吧{:10_266:} {:10_266:}
from msedge.selenium_tools import Edge, EdgeOptions
MSEDGE_PATH = r"C:\Program Files (x86)\Microsoft\Edge Beta\Application\msedge.exe"
MSEDGE_DRIVER_PATH = './msedgedriver.exe'#https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
def init_imitate_edge_driver() -> Edge:
options = EdgeOptions()
options.use_chromium = True
options.binary_location = MSEDGE_PATH
options.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = Edge(options=options, executable_path=MSEDGE_DRIVER_PATH)
driver.execute_cdp_cmd(
"Page.addScriptToEvaluateOnNewDocument", {
"source":
"""
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
return driver
if __name__ == "__main__":
driver = init_imitate_edge_driver()
driver.get('https://fishc.com.cn/thread-189822-1-1.html') MSEDGE_PATH
MSEDGE_DRIVER_PATH
自己改 环境变量没用 就直接写相对或者绝对路径 kogawananari 发表于 2021-2-2 17:44
MSEDGE_PATH
MSEDGE_DRIVER_PATH
自己改 环境变量没用 就直接写相对或者绝对路径
蟹蟹,好了已经{:10_297:} driver.execute_cdp_cmd(
"Page.addScriptToEvaluateOnNewDocument", {
"source":
"""
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
return driver
是否加个备注:自动机webdriver运行一个js脚本设置...?
页:
[1]