实战爬取Plati官网游戏实时最低价格-Python

  1. 需要修改url中的id_r="这个”,这个id需要从Battlefield V (plati.ru)中获取,其实也是这个链接中的#s24235。
  2. 配合了e-mail推送,其实这个e-mail推送可以利用邮箱的短信提醒来达成发送信息到手机号的目的,主要的还是get_rmb(),直接上代码吧。

 

 1 #!/usr/bin/python
 2 # -*- coding: UTF-8 -*-
 3 import requests
 4 import sys
 5 import re
 6 import json
 7 import smtplib
 8 
 9 
10 ##############################配置###############################
11 FROM = ''        #发送者邮箱
12 PASSWORD = ''    #邮箱授权密码
13 TO = ''        #接收者邮箱
14 HOST = 'smtp.163.com'            #SMTP服务器
15 PORT = '465'                     #SMTP服务器SSL端口
16 #################################################################
17 
18 #############################发送邮件##############################
19 def sent_email(theme,context): 
20     try:
21         smtpObj = smtplib.SMTP_SSL(HOST, PORT)
22         smtpObj.login(FROM, PASSWORD)
23         msg = '\n'.join(['From: {}'.format(FROM), 'To: {}'.format(TO), 'Subject: {}'.format(theme), '', context])
24         smtpObj.sendmail(FROM, TO, msg=msg.encode('utf-8'))
25         print("邮件发送成功")
26 
27     except smtplib.SMTPException:
28         print("Error: 无法发送邮件")
29 #################################################################
30 
31 #############################代码区###############################
32 def get_rmb(url):
33     try:
34         headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36 Edg/92.0.902.55"}
35         html = requests.get(url, headers=headers)
36         html.encoding = 'utf-8-sig'
37         RUB = re.search(r'product-price-inner"><div>(.*?)<span>,',html.text).group(1)
38         RMB = "%.1f"%(int(RUB)/12.7)
39         return RMB
40     except:
41         print("获取id和name失败")
42         sys.exit()
43 
44 
45 
46 url1 = "https://plati.ru/asp/block_goods_r.asp?id_r=23833&sort=price&page=1&rows=20&curr=RUB" #战地1
47 url2 = "https://plati.ru/asp/block_goods_r.asp?id_r=24235&sort=price&page=1&rows=20&curr=RUB" #战地5
48 RMB1 = get_rmb(url1)
49 RMB2 = get_rmb(url2)
50 sent_email(theme="战地Ⅴ-" + RMB2 + "元",context="战地1-" + RMB1 + "元")

 

 
上一篇:3行Python代码实现图像照片抠图和换底色


下一篇:跟着铁头干混淆4.1 ollvm控制流平坦化基本概念