我使用split在网站上买票,我使用Browser(chrome)
。我要解析的页面是CCD_ 2,我想通过split点击u"预定"
。
但当我运行代码时:
b.find_by_text(u"预定")[order-1].click()
它显示以下错误:
Traceback (most recent call last):
File "/Users/liangxiaoyu/PycharmProjects/shiyanlou/qiangpiao.py", line 54, in <module>
getTicket()
File "/Users/liangxiaoyu/PycharmProjects/shiyanlou/qiangpiao.py", line 44, in getTicket
b.find_by_text(u"预定")[0].click()
File "/usr/local/lib/python2.7/site-packages/splinter/element_list.py", line 44, in __getitem__
self.find_by, self.query))
splinter.exceptions.ElementDoesNotExist
我真的很确定页面中包含文本"预定"
,那么我该怎么办?
您应该注意,只有当您登录并通过提供出发地、目的地和行程数据搜索特定列车时,预订
按钮才会出现。登录后,您可以尝试以下代码。
from splinter import Browser
browser = Browser('chrome')
# Visit URL
url = "https://kyfw.12306.cn/otn/leftTicket/init"
browser.visit(url)
# Find and click the '预订' button
button = browser.find_by_text('预订')[order-1]
# Interact with elements
button.click()