Python爬虫系列之MeiTuan优选商家端商品自动化管理(商品发布、商品排期、订单采集)

小程序爬虫接单、app爬虫接单、网页爬虫接单、接口定制、网站开发、小程序开发> 点击这里联系我们 <

微信请扫描下方二维码

代码仅供学习交流,请勿用于非法用途

直接上代码

# -*- coding:utf-8 -*-
import requests
import datetime
import time
import json
import os
import xlrd
import xlwt
from xlutils.copy import copy'''功能点:1、MeiTuan优选商家端商品自动上架2、MeiTuan优选商家端商品自动排期3、MeiTuan优选商家端商品订单自动采集wx:walei5201314
'''retry = 3
timeout = 20
excelTitle = ["productId", "skuId", "商品名称", "销售区域", "供货价", "库存", "销售单位", "销售日期", "生产日期", "市场价", "坑位"]
excelPwd = os.getcwd() + "/paiqi/"
if not os.path.exists(excelPwd):os.mkdir(excelPwd)
cookie = ""
mallPassportToken = ""def initExcel(path):try:f = xlwt.Workbook()sheet1 = f.add_sheet(u'double', cell_overwrite_ok=True)for i in range(0, len(excelTitle)):sheet1.write(0, i, excelTitle[i])f.save(path)return Trueexcept Exception as e:return Falsedef writeExcel(data, path):print("===========================================================")print(data)print("===========================================================")try:workbook = xlrd.open_workbook(path)sheets = workbook.sheet_names()worksheet = workbook.sheet_by_name(sheets[0])rows_old = worksheet.nrowsnew_workbook = copy(workbook)new_worksheet = new_workbook.get_sheet(0)for j in range(0, len(data)):try:new_worksheet.write(rows_old, j, str(data[j]))except Exception as e:continuenew_workbook.save(path)return Trueexcept Exception as e:passreturn Falsedef dateTots(s):try:return int(time.mktime(time.strptime(s, "%Y/%m/%d"))) * 1000except Exception as e:return Nonedef getHtml(url, headers):for i in range(retry):try:resp = requests.get(url, headers=headers, timeout=timeout)return json.loads(resp.content.decode("utf-8"))except Exception as e:passdef postHtml(url, data, headers):for i in range(retry):try:resp = requests.post(url, headers=headers, data=data, timeout=timeout)return json.loads(resp.content.decode("utf-8"))except Exception as e:passdef updateCookie():global cookieglobal mallPassportTokentry:with open("cookie.txt", "r", encoding="utf-8") as f:fs = f.readlines()cookie = fs[0]except Exception as e:print("启动错误:程序所在目录未读取到 cookie.txt 文件!")exit(0)def mkdir(path):try:if os.path.exists(path):return Trueos.mkdir(path)return Trueexcept Exception as e:passreturn Falsedef getCurrentTime():return str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))def getCurrentDate():return str(time.strftime('%Y-%m-%d', time.localtime(time.time())))def getSechduleRegionList():url = "https://vss-grocery.meituan.com/api/vss/shepherd/schedule/VendorSkuScheduleQueryApiService/searchVendorHistoryScheduleRegion?version="headers = {"mall-passport-token": mallPassportToken,"Content-Type": "application/json","User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.2(0x18000231) NetType/4G Language/zh_CN","mall-login-type": "passport-temp","Referer": "https://servicewechat.com/sssssss5521212/148/page-frame.html","Cookie": cookie}res = postHtml(url, {}, headers)try:return res['data']except Exception as e:passdef tsToDate(ts):if ts:timeArray = time.localtime(int(ts))return str(time.strftime("%Y-%m-%d", timeArray))return ""def getSellPosition(sellPosition):if sellPosition is None or sellPosition == "null":return ""elif str(sellPosition) == "4":return "万人团"elif str(sellPosition) == "3":return "秒杀"elif str(sellPosition) == "2":return "爆品"elif str(sellPosition) == "1":return "常规"return ""def schduleParser(schduleStartTs, schduleEndTs, regionId, regionName, excelPath):url = "https://vss-grocery.meituan.com/api/vss/shepherd/schedule/VendorSkuScheduleQueryApiService/searchScheduleList?version="page = 1while True:data = {"paging": {"offset": (page - 1) * 10,"limit": 10},"skuName": "","scheduleStatus": 0,"saleStartTime": schduleStartTs,"saleEndTime": schduleEndTs}headers = {"mall-passport-token": mallPassportToken,"Content-Type": "application/json","User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.2(0x18000231) NetType/4G Language/zh_CN","mall-login-type": "passport-temp","Referer": "https://servicewechat.com/wx40f6ce973eb82d6b/148/page-frame.html","Cookie": cookie}res = postHtml(url, json.dumps(data), headers)try:scheduleList = res['data']['scheduleList']if scheduleList and len(scheduleList) > 0:for schedule in scheduleList:try:datas = []datas.append(schedule['productId'])datas.append(schedule['skuId'])datas.append(schedule['name'])datas.append(schedule['stock'])datas.append(schedule['unitName'])datas.append(tsToDate(str(schedule['saleDate'])[: 10]))try:datas.append(tsToDate(str(schedule['productProductionDate'])[: 10]) if schedule['productProductionDate'] else "")except Exception as e:datas.append("")try:datas.append(str(schedule['cutlinePrice']) if schedule['cutlinePrice'] else "")except Exception as e:datas.append("")try:datas.append(getSellPosition(str(schedule['sellPosition'])))except Exception as e:datas.append("")writeExcel(datas, excelPath)except Exception as e:passtotal = int(res['data']['total'])if total < 10:breakpage += 1else:breakexcept Exception as e:passreturn Falsedef getBeforeDaysDate(days):threeDayAgo = (datetime.datetime.now() - datetime.timedelta(days=days))return dateTots(str(threeDayAgo.strftime('%Y/%m/%d')))def main():updateCookie()excelPath = excelPwd + getCurrentDate() + ".xls"if status:startTs = getBeforeDaysDate(0)sechduleRegionList = getSechduleRegionList()if sechduleRegionList and len(sechduleRegionList) > 0:for sechduleRegion in sechduleRegionList:try:schduleParser(startTs, endTs, str(sechduleRegion['regionId']), sechduleRegion['regionName'], excelPath)except Exception as e:passelse:print("获取销售地区失败,请检查是否登录过期!")else:print("excel:%s 创建失败!请检查excel是否处于打开状态,如果是请关闭!" % excelPath)if __name__ == '__main__':main()

Python爬虫系列之MeiTuan优选商家端商品自动化管理(商品发布、商品排期、订单采集)相关推荐

  1. Python爬虫系列之MeiTuan网页美食版块商家数据爬取

    Python爬虫系列之MeiTuan网页美食版块商家数据爬取 小程序爬虫接单.app爬虫接单.网页爬虫接单.接口定制.网站开发.小程序开发> 点击这里联系我们 < 微信请扫描下方二维码 代 ...

  2. Python爬虫系列之爬取某社区团微信小程序店铺商品数据

    Python爬虫系列之爬取某社区团微信小程序店铺商品数据 如有问题QQ请> 点击这里联系我们 < 微信请扫描下方二维码 代码仅供学习交流,请勿用于非法用途 数据库仅用于去重使用,数据主要存 ...

  3. Python爬虫系列之爬取猫眼电影,没办法出门就补一下往期电影吧

    前言 今天给大家介绍利用Python爬取并简单分析猫眼电影影评.让我们愉快地开始吧~ 开发工具 Python版本:3.6.4 相关模块: requests模块: pyecharts模块: jieba模 ...

  4. Python爬虫系列之爬取某优选微信小程序全国店铺商品数据

    Python爬虫系列之爬取某优选微信小程序全国商品数据 小程序爬虫接单.app爬虫接单.网页爬虫接单.接口定制.网站开发.小程序开发 > 点击这里联系我们 < 微信请扫描下方二维码 代码仅 ...

  5. 「Python爬虫系列讲解」十一、基于登录分析的 Selenium 微博爬虫

    本专栏是以杨秀璋老师爬虫著作<Python网络数据爬取及分析「从入门到精通」>为主线.个人学习理解为主要内容,以学习笔记形式编写的. 本专栏不光是自己的一个学习分享,也希望能给您普及一些关 ...

  6. python爬虫系列之初识爬虫

    python爬虫系列之初识爬虫 前言 我们这里主要是利用requests模块和bs4模块进行简单的爬虫的讲解,让大家可以对爬虫有了初步的认识,我们通过爬几个简单网站,让大家循序渐进的掌握爬虫的基础知识 ...

  7. python爬取图片教程-推荐|Python 爬虫系列教程一爬取批量百度图片

    Python 爬虫系列教程一爬取批量百度图片https://blog.csdn.net/qq_40774175/article/details/81273198# -*- coding: utf-8 ...

  8. Python爬虫系列:使用selenium+Edge查询指定城市天气情况

    首先发个福利,有个网店正在推出特价优惠<Python程序设计开发宝典>,原价69.0元,特价46.92元,详情查看:https://detail.tmall.com/item.htm?id ...

  9. Python爬虫系列之唯品会商品数据采集

    Python爬虫系列之唯品会商品数据采集 如有疑问点击这里联系我们 微信请扫描下方二维码 代码仅供学习交流,请勿用于非法用途 直接上代码 import requests from queue impo ...

最新文章

  1. 定价是什么意思_茶商给茶叶定价也有潜规则!从定价就能看出,买的不如卖的精...
  2. Nginx的Mainline version、Stable version、Legacy version的版本区别
  3. WPF 基础控件之 DataGrid 样式
  4. 八大排序算法之选择排序算法
  5. 编译原理(三)之语义分析
  6. pycharm创建我的第一个项目
  7. Leaflet文档阅读笔记-Markers With Custom Icons笔记
  8. 百度SEO资源吧emlog模版全套源码
  9. C++_结构体中const使用场景_结构体_毕业设计案例_使用结构体数组_随机数种子---C++语言工作笔记027
  10. 图像模式识别与计算机视觉的,图像处理、计算机视觉和模式识别领域有哪些区别和联系...
  11. 黑马Java微服务十次方项目不加密视频
  12. 完整安装minidwep-gtk教程
  13. 你一生要知道的74幅世界名画…
  14. 如何用python批量下载数据_如何基于Python批量下载音乐
  15. 《大学》修身、齐家、治国、平天下
  16. NTL密码算法开源库(数论库)代码分析项目--综述
  17. 计算两个时间的间隔时长
  18. 系统自带的最便捷的远程控制方法
  19. Deep Crossing
  20. Promise.all、Promise.allSettled、Promise.any、Promise.race

热门文章

  1. 浮点数十六进制转换工具
  2. 深入ES6:箭头函数
  3. c语言海盗分1000个金币,海盗分金币问题及代码实现
  4. OSChina 周五乱弹 —— 又到周五,我想静静
  5. 核雕图案的寓意(下)
  6. 关于AES:加密方式,让你的APK无懈可击,android性能优化和内存优化面试
  7. foxmail中导入网易邮箱联系人方法
  8. 葫芦娃说 | 下一代编解码标准的抉择
  9. java 设计模式 路由器_Java设计模式——工厂模式
  10. 程序员节的过节姿势大全