#!/usr/bin/python # -*- coding: utf-8 -*- from selenium import webdriver import time # browser = webdriver.Firefox() # browser = webdriver.Ie() browser = webdriver.Chrome() browser.get("http://www.baidu.com") browser.find_element_by_id("kw").send_keys(u"selenium") browser.find_element_by_id("su").click() for i in range(4): time.sleep(3) browser.find_element_by_partial_link_text("下一页").click() body = browser.find_element_by_tag_name("body"); if "github" in body.text.encode("utf-8"): print("---Found it---") else: print("---Not Found!---") print("page:" + str(i)) time.sleep(6) browser.quit()