221 lines
8.1 KiB
C#
221 lines
8.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using AllBase;
|
|
|
|
namespace Work
|
|
{
|
|
public class PinduoduoProductCollect
|
|
{
|
|
public ProductDtailBase Product;
|
|
public static List<long> TempIds = new List<long>();
|
|
public ProductCollectBase pb = new ProductCollectBase();
|
|
public string Name, TempHtml = "";
|
|
public bool NoAdd = false;
|
|
public PinduoduoProductCollect(string name, ProductDtailBase product)
|
|
{
|
|
Name = name;
|
|
Product = product;
|
|
}
|
|
|
|
public void Get()
|
|
{
|
|
try
|
|
{
|
|
Getx();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
public void Getx()
|
|
{
|
|
if (TempIds.Contains(Product.FromId) && string.IsNullOrEmpty(TempHtml))
|
|
{
|
|
return;
|
|
}
|
|
else if (!TempIds.Contains(Product.FromId))
|
|
{
|
|
TempIds.Add(Product.FromId);
|
|
}
|
|
string url = BaseClass.PddMobileUrlx + "goods.html?goods_id=" + Product.FromId;
|
|
string refere = BaseClass.PddMobileUrlx;
|
|
string html;
|
|
if (string.IsNullOrEmpty(TempHtml) || !TempHtml.Contains("catID1"))
|
|
{
|
|
Thread.Sleep(2000);
|
|
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("catID1"))
|
|
{
|
|
Thread.Sleep(10000);
|
|
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true);
|
|
}
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("catID1"))
|
|
{
|
|
Thread.Sleep(20000);
|
|
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true);
|
|
}
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("catID1"))
|
|
{
|
|
Thread.Sleep(20000);
|
|
LogSave.Add(Name, "商品详细信息获取异常:" + Product.FromId);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
html = TempHtml;
|
|
}
|
|
|
|
|
|
pb.from = "拼多多";
|
|
pb.id = Product.FromId;
|
|
pb.from_id = Product.FromId;
|
|
LogSave.Add(Name, "获取成功:" + Product.FromId);
|
|
pb.name = BaseRegex.GetStringJson(ref html, "goodsName");
|
|
pb.name_share = BaseRegex.GetStringJson(ref html, "shareDesc");
|
|
pb.content_pinduoduo = BaseRegex.GetStringJson(ref html, "goodsDesc");
|
|
string temp = BaseRegex.GetMatchRegexString(ref html, @"""topGallery"":\[(.*?)\]");
|
|
var m = BaseRegex.GetMatchRegex(ref temp, @"""([^""]+?)""");
|
|
for (int i = 0; i < m.Count; i++)
|
|
{
|
|
string img = m[i].Groups[1].Value.Replace("@750w_1l_50Q", "");
|
|
pb.Images.Add(img);
|
|
//UpPinduoduoProductSet.AddImage(img, img, 640, 640);
|
|
}
|
|
temp = BaseRegex.GetMatchRegexString(ref html, @"""detailGallery"":\[(.*?)\]");
|
|
m = BaseRegex.GetMatchRegex(ref temp, @"""url"":""([^""]+?)"",""width"":([\d]+),""height"":([\d]+)");
|
|
string content = "";
|
|
for (int i = 0; i < m.Count; i++)
|
|
{
|
|
string img = m[i].Groups[1].Value.Replace("@750w_1l_50Q", "");
|
|
int width = int.Parse(m[i].Groups[2].Value);
|
|
int height = int.Parse(m[i].Groups[2].Value);
|
|
content += "<img src='" + img + "'>";
|
|
//UpPinduoduoProductSet.AddImage(img, img, width, height);
|
|
}
|
|
string strx = "\"skus\":\\[\\{\"skuID\":[\\s\\S]+?,\"hdThumbUrl\"";
|
|
var Skux = BaseRegex.GetMatchRegex(ref html, strx);
|
|
string skustr = "";
|
|
if (Skux.Count > 0)
|
|
{
|
|
skustr = Skux[0].Value;
|
|
}
|
|
|
|
//m = BaseRegex.GetMatchRegex(ref html, @"\{""skuID"".*?""\}\](.*?)\}");
|
|
|
|
m = BaseRegex.GetMatchRegex(ref skustr, "(\"skuId\":[\\s\\S]+?\"groupSkuUnitPrice\":)");
|
|
if (m.Count == 0)
|
|
{
|
|
m = BaseRegex.GetMatchRegex(ref skustr, "(\"skuId\":[\\s\\S]+?\"skuExpansionPrice\":)");
|
|
}
|
|
for (int i = 0; i < m.Count; i++)
|
|
{
|
|
string list = m[i].Groups[0].Value;
|
|
SkuMapBase s = new SkuMapBase();
|
|
s.id = BaseRegex.GetLongJson(ref list, "skuID");
|
|
s.price = BaseRegex.GetDecimalJson(ref list, "groupPrice");
|
|
if (s.price < 1)
|
|
continue;
|
|
s.no_group_price = BaseRegex.GetDecimalJson(ref list, "normalPrice");
|
|
int num = BaseRegex.GetIntJson(ref list, "quantity");
|
|
s.number = BaseRegex.GetIntJson(ref list, "isOnSale") == 1 ? 99 : 0;
|
|
if (s.number > num)
|
|
s.number = num;
|
|
s.prop_image = BaseRegex.GetStringJson(ref list, "thumbUrl");
|
|
if (!string.IsNullOrEmpty(s.prop_image))
|
|
s.prop_image = s.prop_image.Replace("@750w_1l_50Q", "");
|
|
//UpPinduoduoProductSet.AddImage(s.prop_image, s.prop_image, 0, 0);
|
|
s.name = GetName(list, ref pb, s.prop_image);
|
|
pb.SkuMaps.Add(s);
|
|
}
|
|
|
|
pb.cat1 = BaseRegex.GetIntJson(ref html, "catID1");
|
|
pb.cat2 = BaseRegex.GetIntJson(ref html, "catID2");
|
|
pb.cat3 = BaseRegex.GetIntJson(ref html, "catID3");
|
|
Product.Cat1 = pb.cat1;
|
|
Product.Cat2 = pb.cat2;
|
|
Product.Cat3 = pb.cat3;
|
|
pb.content = content;
|
|
pb.price = Product.Price;
|
|
if (pb.price == 0 && pb.SkuMaps.Count > 0)
|
|
pb.price = pb.SkuMaps[0].price;
|
|
pb.saleCount = BaseRegex.GetIntJson(ref html, "sales");
|
|
|
|
|
|
|
|
//if (!UpPinduoduoProductSet.TaobaoProductTemp.ContainsKey(pb.from_id))
|
|
//{
|
|
// try
|
|
// {
|
|
// UpPinduoduoProductSet.TaobaoProductTemp.Add(pb.from_id, pb);
|
|
// }
|
|
// catch
|
|
// {
|
|
// }
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetName(string list, ref ProductCollectBase pb, string image)
|
|
{
|
|
string temp = "";
|
|
//var m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_key"":""([^""]+?)"",""spec_value"":""([^""]+?)""\}");
|
|
var m = BaseRegex.GetMatchRegex(ref list, "\"spec_key\":\"([^,]+)\",\"spec_value\":\"([^,]+)\"");
|
|
if (m.Count == 0)
|
|
{
|
|
m = BaseRegex.GetMatchRegex(ref list, "\"spec_key\":([^,]+),\"spec_value\":([^,]+)");
|
|
}
|
|
|
|
for (int i = 0; i < m.Count; i++)
|
|
{
|
|
temp += m[i].Groups[1].Value + ":" + m[i].Groups[2].Value + ";";
|
|
bool had = false;
|
|
PropBase p = new PropBase();
|
|
for (int j = 0; j < pb.Props.Count; j++)
|
|
{
|
|
if (pb.Props[j].name == m[i].Groups[1].Value)
|
|
{
|
|
had = true;
|
|
p = pb.Props[j];
|
|
break;
|
|
}
|
|
}
|
|
if (!had)
|
|
{
|
|
p = new PropBase();
|
|
p.name = m[i].Groups[1].Value;
|
|
pb.Props.Add(p);
|
|
}
|
|
had = false;
|
|
for (int j = 0; j < p.Values.Count; j++)
|
|
{
|
|
if (p.Values[j].name == m[i].Groups[2].Value)
|
|
{
|
|
p.Values[j].image = image;
|
|
p.Values[j].image_from_url = image;
|
|
had = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!had)
|
|
{
|
|
PropValueBase pv = new PropValueBase();
|
|
pv.name = m[i].Groups[2].Value;
|
|
pv.image = image;
|
|
pv.image_from_url = image;
|
|
p.Values.Add(pv);
|
|
}
|
|
}
|
|
return temp;
|
|
}
|
|
}
|
|
}
|