selenium+python(第一个小实验)

上一篇 / 下一篇  2016-09-18 23:41:08 / 个人分类:selenium+python

查了N多资料,总于找到我需要的一个完整的学习selenium+python的资料,以后所有的学习都将使用该学习教程来实验,http://www.cnblogs.com/fnng/p/3160606.html,在此多谢虫师的分享。


fromseleniumimportwebdriver

browser = webdriver.Firefox()

browser.get("http://www.baidu.com")
print("this steep")
browser.find_element_by_id("kw").send_keys("selenium")
print("this steep")
browser.find_element_by_id("su").click()
print("this steep")

browser.quit()
使用以上程序可打开百度并search selenium这个关键词。因为在调用Firefox的
时候,程序进程很慢,一直担心调用不成功,因此在其中加入了print检查点来实现
是否执行到该步骤。
说明:其中的kw和su都是通过页面检查得来的ID值,这个可以通过页面检查来查看。


以下则是通过chrome来实现的,使用chrome来实现则会比Firefox实现快很多。
fromseleniumimportwebdriver
importtime
browser = webdriver.Chrome()
inporthttp =raw_input("please input one the one the add.")
browser.get(inporthttp)
print("this steep")
browser.find_element_by_id("kw").send_keys("selenium")
print("this steep")
browser.find_element_by_id("su").click()
print("this steep")
printbrowser.title
browser.quit()
其中引入了用户输入的节点inporthttp =raw_input("please input one
the one the add."),当然这个节点可以自己来定义。
加入了printbrowser.title,当程序执行过快,或者执行者不在的时候,可以通过
该命令来打印出我们所执行后的结果。

TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-19  
   1234
567891011
12131415161718
19202122232425
262728293031 

我的存档

数据统计

  • 访问量: 24728
  • 日志数: 5
  • 建立时间: 2016-09-18
  • 更新时间: 2016-09-21

RSS订阅

Open Toolbar