1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 """ 4 @desc: 操作浏览器 5 6 """ 7 from selenium import webdriver 8 import time 9 import logging 10 11 logging.basicConfig(level=logging.INFO) 12 13 14 baidu = "http://www.baidu.com" 15 dr = webdriver.Firefox() 16 dr.get(baidu) 17 18 dr.set_window_size(600, 800) 19 time.sleep(3) 20 logging.info(u"设置浏览器高度为 600x800") 21 22 dr.set_window_position(300, 300) 23 time.sleep(3) 24 logging.info(u"设置浏览器在屏幕上的停放位置为(300,300)") 25 26 dr.maximize_window() 27 logging.info(u"设置浏览器最大化") 28 29 dr.get("http://www.taobao.com") 30 31 dr.back() 32 logging.info(u"上一页:回到百度页面") 33 34 dr.forward() 35 logging.info(u"下一页:淘宝") 36 37 dr.quit() 38 logging.info(u"浏览器退出") 39 40 logging.info(u"Selenium 更多的功能等待你探索,加油吧!")
时间: 2024-11-05 15:45:13