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


需要修改url中的id_r=”这个”,这个id需要从Battlefield V (plati.ru)中获取,其实也是这个链接中的#s24235。

配合了e-mail推送,其实这个e-mail推送可以利用邮箱的短信提醒来达成发送信息到手机号的目的,主要的还是get_rmb(),直接上代码吧。

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
import sys
import re
import json
import smtplib
 
 
##############################配置###############################
FROM = ''        #发送者邮箱
PASSWORD = ''    #邮箱授权密码
TO = ''        #接收者邮箱
HOST = 'smtp.163.com'            #SMTP服务器
PORT = '465'                     #SMTP服务器SSL端口
#################################################################
 
#############################发送邮件##############################
def sent_email(theme,context): 
    try:
        smtpObj = smtplib.SMTP_SSL(HOST, PORT)
        smtpObj.login(FROM, PASSWORD)
        msg = '\n'.join(['From: {}'.format(FROM), 'To: {}'.format(TO), 'Subject: {}'.format(theme), '', context])
        smtpObj.sendmail(FROM, TO, msg=msg.encode('utf-8'))
        print("邮件发送成功")
 
    except smtplib.SMTPException:
        print("Error: 无法发送邮件")
#################################################################
 
#############################代码区###############################
def get_rmb(url):
    try:
        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"}
        html = requests.get(url, headers=headers)
        html.encoding = 'utf-8-sig'
        RUB = re.search(r'product-price-inner"><div>(.*?)<span>,',html.text).group(1)
        RMB = "%.1f"%(int(RUB)/12.7)
        return RMB
    except:
        print("获取id和name失败")
        sys.exit()
 
 
 
url1 = "https://plati.ru/asp/block_goods_r.asp?id_r=23833&sort=price&page=1&rows=20&curr=RUB" #战地1
url2 = "https://plati.ru/asp/block_goods_r.asp?id_r=24235&sort=price&page=1&rows=20&curr=RUB" #战地5
RMB1 = get_rmb(url1)
RMB2 = get_rmb(url2)
sent_email(theme="战地Ⅴ-" + RMB2 + "元",context="战地1-" + RMB1 + "元")
暂无评论

发送评论 编辑评论


				
上一篇
下一篇