1688商品采集

This commit is contained in:
wule committed 2026-03-18 20:45:32 +08:00
1 parent 53736cff6e
commit c489c30bf1
35 files changed
+4095 -254

No files matched your search

+97
View File
@@ -6,6 +6,7 @@
*/
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@@ -673,6 +674,102 @@ namespace AllBase
return temp;
}
public static string GetOneJsonObjStrJson(ref string html, string reg)
{
return GetJsonObjStrJson(ref html, reg).FirstOrDefault();
}
public static System.Collections.Generic.List<string> GetJsonObjStrJson(ref string html, string reg, int level = 0)
{
System.Collections.Generic.List<string> rstLst = new System.Collections.Generic.List<string>();
if (html == null)
return rstLst;
string htmlTmp = html.Replace("\\{", "\\这里是正花括号占位符").Replace("\\}", "\\这里是反花括号占位符");
retry:
string lvStr = "";
if (level == 1)
{
lvStr += "\"";
}
var index1 = htmlTmp.IndexOf("\"" + reg + "\":" + lvStr + "{");
if (index1 < 0)
return rstLst;
htmlTmp = htmlTmp.Substring(index1 + ("\"" + reg + "\":" + lvStr + "{").Length - 1);
// 括号计数
int braceNum = 0;
//string rst = "{";
//while (htmlTmp.Length > 0)
for (int i = 0; i < htmlTmp.Length; i++)
{
//rst += htmlTmp.Substring(0, 1);
//if (htmlTmp.StartsWith("{"))
// braceNum++;
//else if (htmlTmp.StartsWith("}"))
// braceNum--;
if (htmlTmp[i] == '{')
braceNum++;
else if (htmlTmp[i] == '}')
braceNum--;
//htmlTmp = htmlTmp.Substring(1);
if (braceNum == 0)
{
rstLst.Add(htmlTmp.Substring(0, i + 1).Replace("\\这里是正花括号占位符", "\\{").Replace("\\这里是反花括号占位符", "\\}"));
htmlTmp = htmlTmp.Substring(i + 1);
//rstLst.Add(rst.Replace("\\这里是正花括号占位符", "\\{").Replace("\\这里是反花括号占位符", "\\}"));
break;
}
// 循环完了还没结果返回空列表
if (i == htmlTmp.Length - 1)
return rstLst;
}
if (htmlTmp.Length > 0)
goto retry;
return rstLst;
}
public static System.Collections.Generic.List<string> GetJsonArrStrJson(ref string html, string reg)
{
System.Collections.Generic.List<string> rstLst = new System.Collections.Generic.List<string>();
if (html == null)
return rstLst;
string htmlTmp = html.Replace("\\[", "\\这里是正方括号占位符").Replace("\\]", "\\这里是反方括号占位符");
retry:
var index1 = htmlTmp.IndexOf("\"" + reg + "\":[");
if (index1 < 0)
return rstLst;
htmlTmp = htmlTmp.Substring(index1 + ("\"" + reg + "\":[").Length);
// 括号计数
int braceNum = 1;
string rst = "[";
while (htmlTmp.Length > 0)
{
rst += htmlTmp.Substring(0, 1);
if (htmlTmp.StartsWith("["))
braceNum++;
else if (htmlTmp.StartsWith("}"))
braceNum--;
htmlTmp = htmlTmp.Substring(1);
if (braceNum == 0)
{
rstLst.Add(rst.Replace("\\这里是正方括号占位符", "\\[").Replace("\\这里是反方括号占位符", "\\]"));
break;
}
}
if (htmlTmp.Length > 0)
goto retry;
return rstLst;
}
/// <summary>
/// 获取值
/// </summary>