python chrome
from selenium.webdriver.chrome.options
import Options
from selenium import webdriver
wd = webdriver.Chrome()#打开有界面浏览器
wd.maximize_window()#最大化浏览器
wd.execute_script("var q=document.documentElement.scrollTop=980") #向下滚动
url1="https://www.abc.com"
wd.execute_script("window.open('%s')"%(url1)) # 打开新的选项卡来打开指定网页
wa1=wd.current_window_handle#得到当前选项卡句柄
waall=wd.window_handles#得到所有选项卡的句柄
wd.switch_to.window(waall[-1])#切换到最后的选项卡
# 无界面 def nobrowser():
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driverChrome = webdriver.Chrome(executable_path="chromedriver.exe",options=chrome_options) #path指定使用具体的chromedriver.exe
return driverChrome
调用:
wd=nobrowser()
url="https://www.baidu.com"
wd.get(url)
# 有界面 def browser():
driverChrome = webdriver.Chrome(executable_path="“chromedriver.exe")
return driverChrome
调用:
wd=nobrowser()
url="https://www.baidu.com"
wd.get(url)
无界面firefox
from selenium.webdriver.firefox.options import Options
ff_option = Options()
ff_option.add_argument('-headless')