python splinter 火车票抢购

今天抢火车票未成功,因此而希望能够找到一个脚本处理火车票订购自动化

引用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 版本,所以还是建议还是直接下载最新的包,或者选择自己需要的包进行安装

该脚本使用细节可以查看

http://youerning.blog.51cto.com/10513771/1719159/

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值