Coder Social home page Coder Social logo

coupon's Introduction

博客地址——Python脚本实现抢券

参数获取

要实现发送请求抢券,需要获取券的URL,并定制请求头Request Headers

下面所有参数都来自Chrome的开发者工具。大多浏览器都有开发者工具,可以按需选择

准备步骤:

  1. 登录网站
  2. 进入抢券页面
  3. 打开开发者工具(Chrome的快捷键是F12)
  4. 切换到Network栏

获取券的URL

在上面准备步骤的基础上,点击想要抢的券,这时Name栏底部会出现一个新的链接,点击这个链接,而我们需要的参数就来自Header

复制Request URL

https://act-jshop.jd.com/couponSend.html? ......

获取Cookie

也是在上面这个页面中,下翻在Request Header中,有一个Cookie的参数,复制下来

ipLoc-djd=1-72-2799-0; ipLocation=%u5317%u4EAC; areaId=1; ......

获取券的Referer

同上,复制Referer参数

https://sale.jd.com/act/hznk5FbYfOTiEp.html

运行

直接在命令行运行

python main.py

看见上面这几个字气不气???

后记

终于抢到券了,但是。。。

最后一天突然券的数量变多了,完全不用抢

这。。。骗子!

不过看到这行字还是挺开心的

有些时候要同时抢几张券,所以把参数改成了列表

# 券的URL
requestUrls = ["https://act-jshop.jd.com/couponSend.html?callback=jQuery2891171&roleId=8781460&key=48b40c64619a4bc9a3912c98d5a94fed&_=1510055639531","https://act-jshop.jd.com/couponSend.html?callback=jQuery6218594&roleId=8725660&key=a606cfe7c5b045d1b5e58b43a59fd9b1&_=1510056463018"]

# 券的Referer
referers = ["https://sale.jd.com/act/bD1USlOE8n.html","https://sale.jd.com/act/bD1USlOE8n.html"]

# 如果到预定时间就开始发送请求,然后打印结果
        if now == scheduled_time:
            for i in range(len(requestUrls)):
                session.headers['Referer'] = referers[i]
                r = session.get(requestUrls[i])
                print(r.text)
            break

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.