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

132 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AllBase;
using Work.CollectClass;
namespace Work.Api
{
public class BigDataCenter
{
public string Name;
public static Dictionary<string,List<string>> Keywords = new Dictionary<string, List<string>>();
public static List<string> KeywordTemp = new List<string>();
public static int PriceBegin = 0, PriceEnd = 0, SoldBegin = 0, SoldEnd = 0,Count=0;
public static bool Taobao = false, Alibaba = false, Pinduoduo = false;
public static List<TaobaoProductBase> ProductTemp = new List<TaobaoProductBase>();
public static List<string> KeywordString = new List<string>();
public BigDataCenter(string name)
{
Name = name;
}
public void Get()
{
string url = "http://pcat.qixiaoke.com/taobao/pinduoduo_search.php";
for (int i = 0; i < KeywordString.Count; i++)
{
string key = KeywordString[i];
int count = Keywords.ContainsKey(key) ? Keywords[key].Count : Count;
List<string> titles = Keywords.ContainsKey(key) ? Keywords[key] : new List<string>();
string data = UserLogin.GetSignaturex();
data += "&keyword=" + GetHtml.UrlEncodeUtf8(key) + "&count=" + count;
data += "&pi=" + PriceBegin + "&pa=" + PriceEnd + "&si=" + SoldBegin + "&sa=" + SoldEnd;
if (Taobao)
{
string html = GetHtml.PostUtf8(url, data + "&sid=1");
Data(html, titles);
}
if (Alibaba)
{
string html = GetHtml.PostUtf8(url, data + "&sid=3");
Data(html, titles);
}
if (Pinduoduo)
{
string html = GetHtml.PostUtf8(url, data + "&sid=2");
Data(html, titles);
}
}
}
public void Data(string html, List<string> list)
{
html = GetHtml.Decode(html).Replace("\\/","/");
var m = BaseRegex.GetMatchRegex(ref html, @"""attrs"":\{([^\}]+?)\}");
for (int j = 0; m != null && j < m.Count ; j++)
{
if(list.Count>0 && j>= list.Count)
break;
string li = m[j].Groups[1].Value;
TaobaoProductBase t = new TaobaoProductBase();
t.FromId = BaseRegex.GetLongJson(ref li, "product_id");
int tp = BaseRegex.GetIntJson(ref li, "site_id");
t.FromType = "淘宝";
if (tp == 2)
t.FromType = "内部数据";
if (tp == 3)
t.FromType = "阿里巴巴";
t.Titlte = BaseRegex.GetStringJson(ref li, "name");
t.Cat1 = BaseRegex.GetIntJson(ref li, "cat1");
t.Cat2 = BaseRegex.GetIntJson(ref li, "cat2");
t.Cat3 = BaseRegex.GetIntJson(ref li, "cat3");
t.CatId = BaseRegex.GetIntJson(ref li, "cat_id");
if (t.Cat3 != t.CatId)
t.Cat4 = t.CatId;
FromTitleToCat f = new FromTitleToCat();
t.MainCatId = f.GetMainCatId(t.Cat1);
t.MainCatName = f.MainCatName;
if (list.Count > j)
{
t.Build = true;
t.Titlte = list[j];
}
t.Price = BaseRegex.GetDecimalJson(ref li, "price_min");
t.SaleCount = BaseRegex.GetIntJson(ref li, "sold_count");
BigDataBuild.Product.Add(t);
ProductTemp.Add(t);
}
}
public string Input(string dir)
{
string message = "无导入数据";
string[] l = Directory.GetFiles(dir);
for (int i = 0; i < l.Length; i++)
{
string name = Path.GetFileNameWithoutExtension(l[i]);
if(string.IsNullOrEmpty(name))
continue;
List<string> keywords = new List<string>();
string[] ll = FileBase.ReadAllLines(l[i]);
for (int j = 0; j < ll.Length; j++)
{
if (string.IsNullOrEmpty(ll[j]) || ll[j].Length>32 || ll[j].Length<20)
continue;
string key = ll[j].Trim().Replace("\t", " ");
if (keywords.Contains(key))
continue;
keywords.Add(key);
}
if (Keywords.ContainsKey(name))
{
Keywords[name] = keywords;
continue;
}
Keywords.Add(name, keywords);
KeywordTemp.Add(name);
message = "导入成功";
}
return message;
}
}
}