python realizes the wechat automatic reminder function of seckill goods (with code)

Technology realization principle: get the specific commodity information of JD, and then use wechat to send reminders

Tool: two microsignals are needed, which are mutual friends

If you want to learn Python or are learning python, there are many Python tutorials, but are they up to date? Maybe you have learned something that someone else probably learned two years ago. Share a wave of the latest Python tutorials in 2020 in this editor. Access to the way, private letter small "information", you can get free Oh!

1. Collect the product url you want

We take JD as an example to obtain the seckill commodity information of JD:

First of all, we open JD on the web page and search for the products we want. Here I take my recent purchases as an example:

We need to find its product information, open the developer mode of browser, and then we need to choose our own shipping address. At this time, we will send some interface requests:

We choose a useful product information interface:

Find the information interface of the desired product to determine whether it is available:

The general rule is: if there is "no goods" character information in this interface book, it is the out of stock status. Otherwise, it is the out of stock status. You can send a product link to purchase.

Now we have successfully obtained the url information of the product. The next step is to set up wechat.

2. Set wechat notification

Wechat informs us that we need two wechat accounts, one as sender and the other as receiver. These two accounts need to be friends with each other.

Note: wechat as the sender may have registration time requirements (wechat seems to set rules: if the account is registered later than a certain period of time, it will no longer have the function of web wechat login)

Here we use the itchat module to simulate wechat login:

import itchat


The hotload parameter is set to True to remember the status of the first login, and the next login does not need to scan the code.

Execute the above code to generate the login QR code. You only need to scan the code to login.

Next we need to find the notified account:

# Find the object to send
users = itchat.search_friends(name='God like man')


You can search the friend information by using the wechat name or the note name of the friend. Next, we get the information of the sending object:

[{'Uin': 0,

'UserName': '@131572fb0f21d053055ba1caebd1c3089178a1ccafbf320bb72599c4d04a7e20',

'NickName': 'I',

'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=670180178&username=@131572fb0f21d053055ba1caebd1c3089178a1ccafbf320bb72599c4d04a7e20&skey=@crypt_32bfc8c4_05d6f5196800a0aba56d8b80af69f09e',

'ContactFlag': 1, 'MemberCount': 0, 'MemberList': [], 'RemarkName': 'God like man', 'HideInputBarFlag': 0, 'Sex': 1, 'Signature': 'Disappear in the dark', 'VerifyFlag': 0, 'OwnerUin': 0, 'PYInitial': 'W', 'PYQuanPin': 'wu', 'RemarkPYInitial': 'SYYDNZ', 'RemarkPYQuanPin': 'shenyiyangdenanzi', 'StarFriend': 0, 'AppAccountFlag': 0, 'Statues': 0, 'AttrStatus': 33657021, 'Province': 'Shanghai', 'City': 'Huangpu', 'Alias': '', 'SnsFlag': 1, 'UniFriend': 0, 'DisplayName': '', 'ChatRoomId': 0, 'KeyWord': '', 'EncryChatRoomId': '', 'IsOwner': 0}]


We need to get the UserName field for sending information, that is, the specific ID of the sending object

# Get the ID
userName = users[0]['UserName']


Then we can send the second kill message.

3. Realize the notice of goods grabbing

First, we need to access the data interface of JD, that is, the url we got in the first step. Next, we need to visit it to get the returned interface data:

import requests
url = ",830,863&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=&pduid=479124268&ch=1&callback=jQuery3588468"
headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/531.36",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
            "Connection": "keep-alive"
respone = requests.get(url, headers=headers)


After we get the data, we can judge whether there is a "no goods" character in the data. If not, we can use itchat to send the flash purchase information:

if (response.text.find('No goods') > 0):
    print('Temporarily unavailable: ' + skuidUrl)
    print('You have a regular rush,Click buy now:' + skuidUrl)
    itchat.send("You've got a regular rush,Click buy now:\n{}".format(skuidUrl),
    flag += 1


We need to intercept the skuid on the original url for this information, and then splice it:

import re
pattern = re.compile("skuId=(\d+)&")
url = ",830,863&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=&pduid=479124268&ch=1&callback=jQuery3588468"
result = pattern.findall(url)
skuidUrl = '' + result[0] + '.html'


In this way, our regular rush purchase is completed!


Finally, we can set a while loop outside the access. If there is no goods, we will send the access request all the time. If OK, we will break!

Attached with the flash map:


All you need to do is click the flash link to buy directly!

Keywords: Python xml Windows

Added by Pastulio on Mon, 27 Apr 2020 10:54:48 +0300