今天抢火车票未成功,因此而希望能够找到一个脚本处理火车票订购自动化
引用git上一位朋友写的代码
https://github.com/Akagi201/learning-python/blob/master/splinter/huoche.py
借用splinter实现浏览器的点击事件
以下只讲借用splinter实现流程
系统 mac MacBook (Retina, 12-inch, Early 2016)
1.安装splinter
pip installl splinter
2.查看本机是否安装了chromedriver (笔者借用的chrome浏览器)
若没有,打开一下链接
https://chromedriver.storage.googleapis.com/index.html
查看符合自己浏览器版本的chromedriver即刻,笔者使用的chrome版本是55,刚开始看到2.9就点了进去,然后没找到后来发现支持版本55在2.2.7下面,
这里可以查看chromedriver最新版本
https://sites.google.com/a/chromium.org/chromedriver/downloads)
提示:倘若版本号chromedriver不支持chrome当前版本便会引发以下错误
Traceback (most recent call last):
File "test.py", line 29, in <module>
main()
File "test.py", line 11, in main
browser = Browser()
File "/usr/local/lib/python2.7/site-packages/splinter/browser.py", line 63, in Browser
return driver(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/splinter/driver/webdriver/chrome.py", line 31, in __init__
self.driver = Chrome(chrome_options=options, **kwargs)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 408, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 440, in _request
resp = self._conn.getresponse()
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1136, in getresponse
response.begin()
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 417, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''
笔者刚开始图省事然后直接用 brew install chromedriver 安装,结果导致版本号过低,不支持笔者电脑安装的chrome 版本,所以还是建议还是直接下载最新的包,或者选择自己需要的包进行安装
该脚本使用细节可以查看