参数化按行读取txt,每行默认自带了回车换行操作,导致脚本报错,故而按行读取时,需要去掉默认的'\n'
#coding=utf-8
from selenium import webdriver
import os,time source = open("G:\\seleniums\\data.txt", "r")
values = source.readlines() source.close() for serch in values:
#这里使用了strip去掉每行结束的\n
serch=serch.strip('\n')
browser = webdriver.Ie()
browser.get("http://www.baidu.com")
browser.find_element_by_id("kw1").send_keys(serch)
browser.find_element_by_id("su1").click()
browser.quit()