Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2224366
  • 博文数量: 287
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2130
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-31 14:30
个人简介

自己慢慢积累。

文章分类

全部博文(287)

分类: Python/Ruby

2016-04-16 22:58:02

这个是第一个完成了,比较完整的脚本
登录51job并进行页面校验。
里面涉及到很多小知识,记录下来,作为以后的参考。


点击(此处)折叠或打开

  1. #import selenium
  2. from selenium import webdriver
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. import time
  5. import os
  6. #web=selenium.selenium.webdriver.Chrome()
  7. #web=webdriver.Chrome()

  8. #设置chromedirver的环境(如果在WINDOWS中配置了环境变量,这里就不用配置了)
  9. chromedirver=r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe'
  10. os.environ["webdriver.chrome.dirver"] = chromedirver


  11. #修改chrome的配置,使浏览器不在出现“--ignore-certificate-errors”的提示

  12. option = webdriver.ChromeOptions()
  13. option.add_argument('test-type')
  14. web = webdriver.Chrome(chrome_options=option)

  15. web.get("")


  16. title=web.title
  17. print (title)
  18. if title == "招聘网_人才网_找工作_求职_上前程无忧":
  19.     print ("网站打开正常")
  20. else:
  21.     print ("ERROR:网站无法正常打开")

  22. #智能等待
  23. element=WebDriverWait(web,10).until(lambda web:web.find_element_by_id("username"))

  24. web.find_element_by_id("username").clear()
  25. web.find_element_by_id("username").send_keys("350643474@qq.com")
  26. web.find_element_by_id("userpwd").clear()
  27. web.find_element_by_id("userpwd").send_keys("*****")
  28. #web.find_element_by_css_selector("#main > div.login > form > div.btn > input[type=\"image\"]").click()

  29. #web.find_element_by_tag_name("input").get_attribute('type')=="image".click()
  30. web.find_element_by_class_name("btn").click()

  31. #页面跳转,智能等待
  32. print ("登录跳转")
  33. print (time.strftime("%Y-%m-%d %H:%M:%S"))
  34. element=WebDriverWait(web,10).until(lambda web:web.find_element_by_id("top_username"))
  35. print (time.strftime("%Y-%m-%d %H:%M:%S"))

  36. print ("===the first kind of plan==")
  37. a=web.find_element_by_xpath("//*[@id='tMycontent']/div[1]/div[1]/div[3]/div/h3")
  38. print (a.text)

  39. print ("===the second kind of plan==")
  40. print (web.find_element_by_class_name("tMy_card_name").text)

  41. print ("===the third kind of plan==")
  42. print (web.find_element_by_tag_name("h3").text)

  43. print ("===the fourth kind of plan==")
  44. print (web.find_element_by_class_name("tMy_card_name").find_element_by_tag_name("h3").text)


  45. if web.find_element_by_tag_name('h3').text == "***":
  46.     print ("login succsess")
  47. else:
  48.     print ("\033[1;31;40mERROR: login faild! \033[0m")

阅读(848) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~