Masks can not buy how to do? Python Reptile help you time staring at the automated order! | Force program

Author | vegetable garden wow

Zebian | TANG lead

Head Figure | Download from Eastern IC

Produced | CSDN blog

Immediately go to work, way back, to work on the subway are very much needed masks.

Is also very difficult to buy genuine, fast delivery masks, many pharmacies are sold out.

Also, some of the new store on Taobao masks inventory was written very much, but not shipped, not to get money is to collect personal information, sales are very high a few tens of W W sales. In Jingdong, even if notice of arrival, but often did not notice until it was out on the hunt.

At this point, it is my turn to run for Python reptile!

I stared at the moment to help whether the Jingdong arrival, arrival mail notification immediately! Next, let us together look at how Python Reptile help you staring notice of arrival time, and eventually automated order.

The first step: Python Reptile Arrival Notice

First, let's look at a few results to show:

Sold Out show

Stock show

code show as below:

'''
 jd旗舰店检查到货
'''

import requests
import time

# 有货通知 收件邮箱
mail = '[email protected]'
# 商品的url
url = [
    'https://c0.3.cn/stock?skuId=100011293950&area=19_1607_4773_0&venderId=1000078145&buyNum=1&choseSuitSkuIds=&cat=9192,12190,1517&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=&pduid=1580214678781491106132&ch=1&callback=jQuery4173314',
    'https://c0.3.cn/stock?skuId=34424081673&area=19_1607_3639_0&venderId=656282&buyNum=1&choseSuitSkuIds=&cat=9192,12190,1517&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=&pduid=1580214678781491106132&ch=1&callback=jQuery7815511',
    'https://c0.3.cn/stock?skuId=14567560031&area=6_318_320_44149&venderId=70651&buyNum=1&choseSuitSkuIds=&cat=9847,13533,13534&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=&pduid=1580535906442142991701&ch=1&callback=jQuery660434',
    'https://c0.3.cn/stock?skuId=100011293952&area=19_1607_4773_0&venderId=1000078145&buyNum=1&choseSuitSkuIds=&cat=9192,12190,1517&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=&pduid=1580214678781491106132&ch=1&callback=jQuery5497502',
    'https://c0.3.cn/stock?skuId=11300307432&area=2_2824_51916_0&venderId=646174&buyNum=1&choseSuitSkuIds=&cat=9192,12190,1517&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=&pduid=1580214678781491106132&ch=1&callback=jQuery4188953',
]


def sendMail(url):
    import smtplib
    from email.mime.text import MIMEText
    # email 用于构建邮件内容
    from email.header import Header

    # 用于构建邮件头

    # 发信方的信息:发信邮箱,QQ 邮箱授权码
    from_addr = '[email protected]'
    password = 'alpsneahzhawbfgj'

    # 收信方邮箱
    to_addr = mail

    # 发信服务器
    smtp_server = 'smtp.qq.com'

    # 邮箱正文内容,第一个参数为内容,第二个参数为格式(plain 为纯文本),第三个参数为编码
    msg = MIMEText(url + ' 有口罩啦', 'plain', 'utf-8')

    # 邮件头信息
    msg['From'] = Header(from_addr)
    msg['To'] = Header(to_addr)
    msg['Subject'] = Header('有口罩啦')

    # 开启发信服务,这里使用的是加密传输
    server = smtplib.SMTP_SSL(host=smtp_server)
    server.connect(smtp_server, 465)
    # 登录发信邮箱
    server.login(from_addr, password)
    # 发送邮件
    server.sendmail(from_addr, to_addr, msg.as_string())
    # 关闭服务器
    server.quit()


flag = 0
while (1):
    try:

        session = requests.Session()
        session.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"
        }
        print('第' + str(flag) + '次 ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        flag += 1
        for i in url:
            # 商品url
            skuidUrl = 'https://item.jd.com/' + i.split('skuId=')[1].split('&')[0] + '.html'
            response = session.get(i)
            # print('有货啦! 有货啦! 有货啦! : ' + skuidUrl)
            # sendMail(skuidUrl)
            if (response.text.find('无货') > 0):
                print('无货 : ' + skuidUrl)
            else:
                print('有货啦! 有货啦! 有货啦! : ' + skuidUrl)
                sendMail(skuidUrl)

        time.sleep(5)
    except Exception as e:
        import traceback
        print(traceback.format_exc())
        print('异常')
        time.sleep(10)

the place need to change:

The main changes are the following two places, after the completion of the real-time monitoring.

To send and receive email modify into your own, you can read this CSDN Bowen: "Python automatically send e-mail", https://blog.csdn.net/LeoPhilo/article/details/89074232 .

The second is to monitor commodity URL.

Google Chrome browser, press F12 to open, click on the region where the goods and the need to find the stock at the beginning of the URL, copy, modify or add below.

In this remind everyone, be careful not to put too high frequency modulation to avoid being Jingdong anti-crawlers.

The second step, how to implement automated order reptiles?

Once you have arrived, and how to implement automated order it, and also to avoid panic buying, the program automatically once only buy one?

Upon completion of the first step basis, we enter into the second step, automated order crawlers.

Automated order to obtain the required Cookie:

  • Modify Location

  • method of obtaining

(1) Open Google Chrome, log in Jingdong.

(2) Press F12 to enter my order page, filter out list.action url.

(3) request to find the cookie then fell to copy, modify the line in the code inside.

Finally, we wish everyone can grab a mask and healthy start!

For more details, read CSDN bloggers' vegetable garden wow "series:

Buy masks, Jingdong arrival notice do not fly, python reptile staring at the moment to help you

https://blog.csdn.net/cyz52/article/details/104114438

Jingdong masks reptiles, reptile arrival notification, automated order reptile, python reptile The second

https://blog.csdn.net/cyz52/article/details/104177981

Jingdong masks reptiles, Tutorial, Part III

https://blog.csdn.net/cyz52/article/details/104239558

【End】

Recommended Reading 

isolation is valid? North facing new crown epidemic data visualization analysis and modeling

Iowa election farce stuffed vote App reflection: Why are we so bad in software engineering?

article tells you how to use Python to build a "Google search for" system | enclosed Code

would like to have as one people: How Silicon Valley billionaire's marriage? White was the Prime Minister keep seventy years

Python + elasticsearch: With this super weapon, you can also enroll in the General Assembly poetry! | Bowen Featured

What block chain in the hash in the end is?

You look at every point, I seriously as a favorite

Mengchuo " read the original ", fill in Chinese telecommuting - survey

发布了1704 篇原创文章 · 获赞 4万+ · 访问量 1531万+

Guess you like

Origin blog.csdn.net/csdnnews/article/details/104352148