源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

用Python抢过年的火车票附源码

  • 时间:2020-03-12 13:26 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:用Python抢过年的火车票附源码
前言:大家跟我一起念,Python大法好,跟着本宝宝用Python抢火车票 [b]首先我们需要splinter[/b] 安装: pip install splinter -i [url=http://pypi.douban.com/simple]http://pypi.douban.com/simple[/url] --trusted-host pypi.douban.com 然后还需要一个浏览器的驱动,当然用chrome啦 下载地址: [url=http://chromedriver.storage.googleapis.com/index.html?path=2.20/]http://chromedriver.storage.googleapis.com/index.html?path=2.20/[/url] 根据下载的自己的电脑系统选择下载包,我的windows就用win32了 解压后直接放到C:\Windows\System32目录下,你当然也可以给这个驱动程序弄个环境变量。 注意:我下的驱动版本是2.19的,根据自己需要下载相应版本,我的2.20版本有报错 [b]首先简单的测试一下吧,推荐ipython代替python自带的交互界面[/b]
from splinter.browser import Browser
b = Browser(driver_name="chrome")
b.visit("http://www.baidu.com") ###注意不要去掉http://
然后牛刀小试一下吧,用百度搜索一些东西。比如splinter 在上面我们已经打开百度的网址了  然后我们输入一些像搜索的内容吧 [img]http://files.jb51.net/file_images/article/201512/2015127150959348.png?2015117151022[/img] 由上可以发现,该输入框的name=wd,通过fill似乎只能通过name填充 官方说明: Fill the field identified by ``name`` with the content specified by ``value``. 那就在输入框搜索splinter,当然也可以输入中文,但是最好指定Unicode编码,如u”我”
[url=http://pan.baidu.com/s/1gdTu7cR]http://pan.baidu.com/s/1gdTu7cR[/url]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部