整体框架,先划分成细小功能模块~~,从最简单的开始,介绍
实现循环百度搜索实例:
#coding=utf-8
‘‘‘
Created on 2014??6??9??
@author: 小鱼
‘‘‘
import xlrd
from selenium import webdriver
import time
#excelFile文件物理地址
book=xlrd.open_workbook("E:\Users\Administrator\workspace\SeleniumTest\excelFile.xls")
browser = webdriver.Firefox()
browser.get("http://www.baidu.com/")
time.sleep(3)
#实现百度输入搜索内容
def select(a):
browser.find_element_by_id("kw1").send_keys(a)
time.sleep(2)
browser.find_element_by_id("su1").click();
browser.back()
time.sleep(1)
def excelFile(x,y,z):
sheel_name = book.sheet_by_name(x)
cell_value = sheel_name.cell_value(y,z)
return cell_value
def excelRows(x):
sheel_name = book.sheet_by_name(x)
nrows=sheel_name.nrows
return nrows
def excelColss(x):
sheel_name = book.sheet_by_name(x)
cols=sheel_name.ncols
return cols
rows = excelRows("baidu")
cols = excelColss("baidu")
#循环读取excel文件内容
for r in range(0,rows):
i =0
select(excelFile("baidu",r,i))
print"搜索内容:%s"%excelFile("baidu",r,i)
i=i+1
print"循环读取excel文件结束"
browser.close()
browser.quit()