Files
KJD/Work/Api/CatListPinduoduo.cs
T
2025-06-29 19:38:31 +08:00

70 lines
3.1 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using AllBase;
namespace Work.Api
{
public class CatListPinduoduo
{
public static Dictionary<int, KeyValuesBase> CatIds = new Dictionary<int, KeyValuesBase>();
public ShopChatBase Shop = null;
public void Get()
{
string cookies = Shop == null ? "" : Shop.Cookies;
string url = "https://mms.pinduoduo.com/earth/api/mallInfo/catList?{}";
string refere = "https://mms.pinduoduo.com/Pdd.html";
string html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", cookies);
if (!Directory.Exists("temp"))
Directory.CreateDirectory("temp");
string dir = "temp/cat_pinduoduo";
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
var m = BaseRegex.GetMatchRegex(ref html, @"""id"":([\d]+),""name"":""([^']+?)""");
for (int i = 0; m != null && i < m.Count; i++)
{
int id = int.Parse(m[i].Groups[1].Value);
string name = m[i].Groups[2].Value;
string file = dir + "/" + id + ".tjm";
if (FileBase.Exists(file))
html = FileBase.ReadAllText(file, Encoding.Default);
else
{
url = "https://mms.pinduoduo.com/vodka/v2/mms/categories?parentId=" + id;
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", cookies);
if (!string.IsNullOrEmpty(html))
FileBase.WriteAllText(file, html, Encoding.Default);
}
var mm = BaseRegex.GetMatchRegex(ref html,
@"""cat_id_1"":([\d]+),""cat_id_2"":([\d]+),""cat_id_3"":([\d]+)");
for (int j = 0; mm != null && j < mm.Count; j++)
{
int id2 = int.Parse(mm[j].Groups[2].Value);
file = dir + "/" + id2 + ".tjm";
if (FileBase.Exists(file))
html = FileBase.ReadAllText(file, Encoding.Default);
else
{
url = "https://mms.pinduoduo.com/vodka/v2/mms/categories?parentId=" + id2;
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", cookies);
if (!string.IsNullOrEmpty(html))
FileBase.WriteAllText(file, html, Encoding.Default);
Thread.Sleep(500);
}
var mmm = BaseRegex.GetMatchRegex(ref html,
@"""cat_id_1"":([\d]+),""cat_id_2"":([\d]+),""cat_id_3"":([\d]+)");
for (int k = 0; mmm != null && k < mmm.Count; k++)
{
int id3 = int.Parse(mmm[k].Groups[3].Value);
if (CatIds.ContainsKey(id3))
continue;
CatIds.Add(id3, new KeyValuesBase(id.ToString(), id.ToString(), id2.ToString(), id3.ToString()));
}
}
}
}
}
}