89 lines
4.8 KiB
C#
89 lines
4.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using AllBase;
|
|
using Work.Api;
|
|
|
|
namespace Work.CollectClass
|
|
{
|
|
public class SearchKeywordByAlibaba
|
|
{
|
|
public static string OrderString = "va_tbprofit&descendOrder=true";
|
|
public static List<string> ShopNames = new List<string>();
|
|
public static List<long> Ids = new List<long>();
|
|
public string Name, Keyword = "";
|
|
|
|
public SearchKeywordByAlibaba(string name)
|
|
{
|
|
Name = name;
|
|
}
|
|
|
|
public void GetKeyword(string keyword, ref int webCursor)
|
|
{
|
|
string refere = "https://s.1688.com/selloffer/offer_search.htm?priceStart=" + CollectKeywordByTaobao.MinPrice + "&priceEnd=" +
|
|
CollectKeywordByTaobao.MaxPrice + "&quantityBegin=2&sortType=" + OrderString + "&uniqfield=pic_tag_id&keywords=" +
|
|
GetHtml.UrlEncodeGb2312(keyword) + "&from=taoSellerSearch&n=y";
|
|
List<Thread> ts = new List<Thread>();
|
|
for (int i = 1; i <= CollectKeywordByTaobao.PageTop; i++)
|
|
{
|
|
string url = "https://s.1688.com/selloffer/rpc_async_render.jsonp?startIndex=0&keywords=" +
|
|
GetHtml.UrlEncodeGb2312(keyword) +"&n=y&pageSize=60&sortType=" + OrderString
|
|
+ "&from=taoSellerSearch&rpcflag=new&async=true&filt=y&priceStart=" + CollectKeywordByTaobao.MinPrice +
|
|
"&templateConfigName=taoSearchOfferresultModule&enableAsync=true&quantityBegin=2&qrwRedirectEnabled=false&asyncCount=20&_pageName_=taoSellerSearch&priceEnd=" +
|
|
CollectKeywordByTaobao.MaxPrice + "&offset=8&uniqfield=pic_tag_id&beginPage=" + i;
|
|
string html = GetPostTaobaoHtml.GetUrl(url, refere, false, "");
|
|
html = html.Replace("\\n", " ").Replace("\\\"", "\"").Replace("\\/", "/").Replace("\\'", "'");
|
|
var m = BaseRegex.GetMatchRegex(ref html, @"<li[^>]+t-rank=""([\d]+)""(.+?)</div>[\s]*</div>[\s]*</li>");
|
|
if (m == null || m.Count == 0)
|
|
{
|
|
Thread.Sleep(30 * 1000);
|
|
continue;
|
|
}
|
|
for (int j = 0; m != null && j < m.Count; j++)
|
|
{
|
|
while (CollectKeywordByTaobao.Running && CollectKeywordByTaobao.Waiting)
|
|
Thread.Sleep(100);
|
|
if (!CollectKeywordByTaobao.Running)
|
|
return;
|
|
string list = m[j].Groups[0].Value;
|
|
if (!list.Contains("一件代发"))
|
|
continue;
|
|
string id = BaseRegex.GetMatchRegexString(ref list, @"com/offer/([\d]+)\.html");
|
|
if (string.IsNullOrEmpty(id) )
|
|
continue;
|
|
string title = BaseRegex.GetMatchRegexString(ref list, @"title=""([^']+?)""");
|
|
ProductCollectBase product = new ProductCollectBase();
|
|
product.from_id = long.Parse(id);
|
|
product.from_title = title;
|
|
product.from_name = title;
|
|
product.from_url = "https://detail.1688.com/offer/" + product.from_id + ".html";
|
|
string sold = BaseRegex.GetMatchRegexString(ref list, @"近30天成交([\d]+)");
|
|
if (string.IsNullOrEmpty(sold))
|
|
sold = BaseRegex.GetIntJson(ref list, "tbMonthSales").ToString();
|
|
if (string.IsNullOrEmpty(sold))
|
|
sold = BaseRegex.GetMatchRegexString(ref list, @"<div class=""s-widget-oswtd-row-a"">([\d]+)件</div>");
|
|
product.saleCount = string.IsNullOrEmpty(sold) ? 0 : int.Parse(sold);
|
|
string price = BaseRegex.GetMatchRegexString(ref list, @"""¥[ ]*([\d\.]+?)""");
|
|
product.price = string.IsNullOrEmpty(price) ? 0 : decimal.Parse(price);
|
|
TaobaoProductBase t = new TaobaoProductBase();
|
|
t.FromId = product.from_id;
|
|
t.Titlte = product.from_title;
|
|
t.FromType = "阿里巴巴";
|
|
t.Price = product.price;
|
|
t.SaleCount = product.saleCount;
|
|
t.MainImage = CollectKeywordByTaobao.MainImageCut;
|
|
if (t.Price < CollectKeywordByTaobao.MinPrice || t.Price > CollectKeywordByTaobao.MaxPrice || t.SaleCount < CollectKeywordByTaobao.MinSale || t.SaleCount > CollectKeywordByTaobao.MaxSale)
|
|
continue;
|
|
FromTitleToCat ft = new FromTitleToCat();
|
|
ft.TaobaoProduct = t;
|
|
Threadx.ThreadListWait(ref ts, new Thread(ft.Get), 8);
|
|
|
|
Thread.Sleep(5 * 1000);
|
|
}
|
|
Thread.Sleep(10 * 1000);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|