Python Selenium百度搜索翻页查找文字

#!/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()
posted @ 2020-06-22 08:08  船长博客  阅读(697)  评论(0编辑  收藏  举报
永远相信美好的事情即将发生!