【爬虫】12306自动化购票

上文:

【爬虫】12306查票-CSDN博客

下面是简单的自动化进行抢票,只写到预定票,没有写完登陆,

跳出登陆后与上述代码同理修改即可。

感觉xpath最简单,复制粘贴:

还有很多写法:

官网地址:

🔦 简化写法 | DrissionPage官网

赋代码:

复制代码
from DrissionPage import Chromium
from DrissionPage.common import Actions,Keys
from time import sleep

tab = Chromium(8898).latest_tab
ac = Actions(tab)

# 以下是自动化查询高铁票
tab.get('https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%E5%B9%BF%E5%B7%9E%E5%8C%97,GBQ&ts=%E5%B9%BF%E5%B7%9E%E5%8D%97,IZQ&date=2025-05-20&flag=N,N,Y')
ac.move_to('x=//*[@id="fromStationText"]').click().type('guangzhoubei').type(Keys.ENTER)
sleep(1)
ac.move_to('x=//*[@id="toStationText"]').click().type('guangzhounan').type(Keys.ENTER)
sleep(1)
tab('x=//*[@id="train_date"]').clear()
ac.move_to('x=//*[@id="train_date"]').click().type('2025-05-23').type(Keys.ENTER)
ac.move_to('x=//*[@id="query_ticket"]').click()

ac.move_to('x=//*[@id="ticket_6c000G60350F_04_05"]/td[13]/a').click()
相关推荐
nothing&nowhere10 小时前
用 Python 做问卷数据清洗:无效样本检测与处理实战
开发语言·python·数据清洗·数据处理·问卷星·问卷星脚本·刷问卷
花酒锄作田10 小时前
如何发布自己的 Python 库到 PyPI
python
researcher-Jiang10 小时前
Design Patterns——Template Method入门到情景实战
python·设计模式·模板方法模式
飞猪~14 小时前
LangChain python 版本 第一集
开发语言·python·langchain
2601_9563198815 小时前
最新AI量化提效,先做可验证的小流程
人工智能·python
开飞机的舒克_16 小时前
FastAPI 实战入门:从路由、参数校验到依赖注入的后端开发指南
python·fastapi
霸道流氓气质16 小时前
Kiro 中反编译 JAR 包并分析字节码的流程指南
chrome·python·jar
人工智能时代 准备好了吗17 小时前
AI回答内容进入率监测:引用识别、文本匹配与语义判断
开发语言·人工智能·python
Metaphor69217 小时前
使用 Python 冻结 Excel 文件中的行、列和单元格
开发语言·python·excel