f1 = open("E:\\zxtest\\ddpush.txt", 'r')
lines = f1.readlines() #读取全部内容 ,并以列表方式返回
print lines
for price in lines:
print price,
time.sleep(2)
driver.find_element_by_name("price").send_keys(price)
driver.find_element_by_id("pay").click()
最终price= [‘3\n’, ‘2’],
price='3\n’时,send_keys(price) 会提交一次,后面 click()又会执行一次所以会发起两笔支付
price='2’时,send_keys(price)不会提交一次,后面 click()会执行一次所以只会发起一笔支付
解决办法:
dd = ['3\n', '2\n']
for i in dd:
print i[:-1]
Python中strip()函数也可以用只是:
声明:s为字符串,rm为要删除的字符序列
s.strip(rm) 删除s字符串中开头、结尾处 的 rm字符
s.lstrip(rm) 删除s字符串中开头处的 rm字符
s.rstrip(rm) 删除s字符串中结尾处的 rm字符
注意:
- 当rm为空时,默认开头和结尾的删除空白符(包括’\n’, ‘\r’, ‘\t’, ’ ')
如:
zz=" 123 564 \n "
print zz.strip()
打印结果:
123 564
zz=" 1235126412"
print zz.strip("12")
#打印结果:
12351264#有空格