#!/usr/bin/env
#coding=utf-8
from selenium import webdriver
import time
driver=webdriver.Firefox()
driver.get('http://www.baidu.com')
#driver.find_element_by_xpath("//input[@id='kw']").send_keys("selenium")
#driver.find_element_by_xpath("//div[@id='head']/div/div/div/form/span/input").send_keys("selenium")
driver.find_element_by_xpath("//div[@class='s_form_wrapper']/form/span/input").send_keys("selenium")
#driver.find_element_by_xpath("/html/body/div[3]/div[2]/div/div/div/form/span/input").send_keys("selenium")
#driver.find_element_by_xpath("//a[contains(text(),'新闻')]").click()
#driver.find_element_by_xpath("//a[@href='http://news.baidu.com']").click()
time.sleep(5)
driver.quit()
通过安装firebug和xpath checker:copy xpth 和copy css path辅助学习理解xpth和css定位方式
本文介绍了一种使用Selenium WebDriver进行网页自动化的方法,并通过具体的Python代码实例演示了如何自动打开百度并输入搜索词'selenium'。此外,还推荐了firebug和xpathchecker等工具以帮助理解XPath和CSS选择器的用法。
890

被折叠的 条评论
为什么被折叠?



