python selenium使用方法

# -*- encoding:utf-8 -*-
# 导入模块
from selenium import webdriver
#chrome驱动路径
driver_path = 'D:\chromedriver\chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path)
url = 'https://www.baidu.com'
driver.get(url)
url = 'https://www.163.com'
#新窗口打开
driver.execute_script("window.open('%s')"%url)
#切换到网易窗口
driver.switch_to.window(driver.window_handles[1])
#查看源码
print(driver.page_source)

 

相关文章

© CopyRight 2013-2020 PHPKT.COM Inc.All Rights Reserved.    冀ICP备20001757号-1    模板设计 Power by 孙磊