实例化谷歌浏览器对象:
from selenium import webdriver
# 实例化一个浏览器对象
wb = webdriver.Chrome(executable_path='D:\python\chromedriver_win32\chromedriver.exe')
wb.get('https://www.bilibili.com/')
实例化Microsoft Edge对象:
from selenium import webdriver
# 实例化一个浏览器对象
wb=webdriver.Edge(executable_path='D:\python\edgedriver_win64\msedgedriver.exe')
wb.get('https://www.bilibili.com/')
实例化对象时可能会出现的问题:
1.浏览器窗口闪退:
用import time time.sleep(5),让浏览器多待上一会就好了
from selenium import webdriver
import time
# 实例化一个浏览器对象
wb=webdriver.Edge(executable_path='D:\python\edgedriver_win64\msedgedriver.exe')
wb.get('https://www.bilibili.com/')
time.sleep(5)
2.报错"DeprecationWarning: executable_path has been deprecated":
此错误不耽误程序运行,如果程序因为此错误不能运行,修改代码为:
from selenium import webdriver
from selenium.webdriver.edge.service import Service
# 实例化一个浏览器对象
s=Service('D:\python\edgedriver_win64\msedgedriver.exe')
wb=webdriver.Edge(service_args=s)
wb.get('https://www.bilibili.com/')
3.报错"TypeError: 'module' object is not callable":
检查你的"Chrome"和“Edge”的“C”或“E”有没有大写!chrome和edge是不可调用的。