#初始化,运行Firefox driver,打开浏览器
driver = webdriver.firefox()
#设置浏览器窗口大小
driver.set_window_size(1080,800)
#设置全局操作超时时间
driver.implicitly_wait(10)
#打开网址
driver.get('http://')
案例(12306)
# coding:utf-8
from selenium import webdriver
# 初始化,运行Firefox driver,打开浏览器
driver = webdriver.Firefox()
# 设置浏览器窗口大小
driver.set_window_size(1080, 800)
# 设置全局操作超时时间
driver.implicitly_wait(10)
# 打开网址
driver.get('https://kyfw.12306.cn')
# 出发地选择
driver.find_element_by_id("login_user").click()
driver.find_element_by_id("username").send_keys('pan940825')
driver.find_element_by_id("password").send_keys('p940825')
raw_input((u"请填写验证码图片,完成后继续。。。"))
#出发日期选择
driver.find_element_by_link_text(u"车票预订").click()
driver.find_element_by_css_selector('body > div.cal-wrap > div:nth-child(1) >div.cal-cm > div:nth-child(22) > div').click()
#勾选车次类型为高铁
driver.find_element_by_css_selector("#_u1_station_train_code>li:first-child").click()
#driver.find_element_by_id("query_ticket").click()
#ele = driver.find_element_by_id("ze_56000G431400")
#ele.click()
#print ele.text
while True:
try:
#点击查询按钮
driver.find_element_by_id("query_ticket").click()
ele = driver.find_element_by_id("ZE_56000G431400")
ele.click()
if ele.text in [u'wu','---']:
print(u'暂时无票,继续查询')
time.sleep(1)
else:
print(u'有票,购买')
except:
pass
raw_input('press to exit')
driver.quit() #浏览器退出