码迷,mamicode.com
首页 > 其他好文 > 详细

10.浏览器页面前进和后退

时间:2018-06-06 22:11:29      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:selenium   ESS   com   get   ack   environ   www   format   proxy   

场景

说实话,这两个功能一般不太常用。所能想到的场景大概也就是在几个页面间来回跳转,省去每次都get url。

  • back()
  • forward()

创建test.py写入以下代码

from selenium import webdriver
from time import sleep
import os
#如果浏览器设置代理,删除代理
if ‘HTTP_PROXY‘ in os.environ: del os.environ[‘HTTP_PROXY‘]

dr = webdriver.Chrome()
first_url = ‘http://www.baidu.com‘
print((‘now access {}‘).format(first_url))
dr.get(first_url)
sleep(2)

second_url = ‘http://news.baidu.com‘
print((‘now access {}‘).format(second_url))
dr.get(second_url)
sleep(1)

print((‘back to {}‘).format(first_url))
dr.back()
sleep(1)

print((‘forward to {}‘).format(second_url))
dr.forward()
sleep(1)

print(‘close brower‘)
dr.quit()

 

10.浏览器页面前进和后退

标签:selenium   ESS   com   get   ack   environ   www   format   proxy   

原文地址:https://www.cnblogs.com/luoshuifusheng/p/9146464.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!