写一个大麦网抢票的脚本
时间: 2023-09-02 12:10:20 浏览: 232
基于python的大麦网自动化抢票脚本实现代码
5星 · 资源好评率100%
抢大麦网的票可以使用 Python 编写一个简单的脚本,以下是一个示例:
```python
import requests
import time
import json
# 填写需要抢票的演唱会信息
project_id = "123456"
venue_id = "7891011"
price_id = "121314"
quantity = "2"
cookies = "填写你的登录状态cookies"
# 构造请求头和请求体
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36",
"Referer": f"https://www.damai.cn/project/{project_id}.html",
"Cookie": cookies
}
data = {
"projectId": project_id,
"venueId": venue_id,
"priceId": price_id,
"buyNum": quantity,
"chooseSeats": "",
"dwStatus": "0",
"invoiceParam": "",
"requestToken": "",
"submitToken": "",
"ticketType": "",
"dwDeliveryWay": "",
"promotion": "",
"isNeedInvoice": "",
"invoiceType": "",
"invoiceTitleType": "",
"invoiceTitle": "",
"email": "",
"cardNum": "",
"mobile": "",
"cardMobile": "",
"cardUserName": "",
"cardId": "",
"needCardInfo": "",
"cardInfoCheck": "",
"performId": "",
"performName": "",
"performDate": "",
"venueName": "",
"seatName": "",
"priceName": "",
"isComps": "",
"compsBuyNum": "",
"compsName": "",
"compsMobile": "",
"compsCardNum": "",
"compsCardId": "",
"compsCardUserName": "",
"compsEmail": "",
"compsCardMobile": "",
"compsTicketType": "",
"compsInvoiceParam": "",
"compsInvoiceType": "",
"compsInvoiceTitleType": "",
"compsInvoiceTitle": ""
}
# 开始抢票
while True:
try:
# 发送请求
response = requests.post("https://buy.damai.cn/confirmorder/ajax.aspx", headers=headers, data=data)
result = json.loads(response.text)
if result["Status"] == 200:
print("抢票成功!")
break
else:
print("抢票失败,重新尝试")
except Exception as e:
print("抢票出现异常,重新尝试")
time.sleep(0.5)
```
需要填写的信息包括演唱会的项目 ID、场馆 ID、价格 ID、购买数量和登录状态的 Cookies。在脚本中构造请求头和请求体,然后使用 requests 库发送 POST 请求。如果返回值的 Status 等于 200,则表示抢票成功,否则需要重新尝试。为了防止被封 IP,每次请求之间需要间隔一定时间。
阅读全文