我正在使用splinter在网站上购买我的门票,我使用Browser(chrome)
。我要解析的页面是https://kyfw.12306.cn/otn/leftTicket/init
,
我想点击分段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
我确信该页面包含文字"预定"
,我该怎么办?
答案 0 :(得分:0)
您应该注意,预订
按钮只有在您登录后才会出现,并通过提供出发地,目的地和旅行数据来搜索特定列车。登录后,您可以尝试以下代码。
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()