📄 collectionprogress.cs
字号:
}
else
{
CollectionCommon collectionCommon = new CollectionCommon();
if (!DataValidator.IsUrl(this.m_CollectionItemInfo.Url))
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "采集项目的URL不是正确地址!</li>";
}
else
{
Uri url = new Uri(this.m_CollectionItemInfo.Url);
string httpPage = collectionCommon.GetHttpPage(url, this.m_CollectionItemInfo.CodeType);
if (string.IsNullOrEmpty(httpPage))
{
this.m_ErrorInfo = "<li>不能获得" + this.m_CollectionItemInfo.ItemName + "项目的" + this.m_CollectionItemInfo.Url + "源代码,有可能对方屏蔽了端口或本服务器屏蔽了端口!</li>";
}
else
{
string str2 = collectionCommon.GetInterceptionString(httpPage, infoById.ListBeginCode, infoById.ListEndCode);
if (string.IsNullOrEmpty(str2))
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目列表设置错误!</li>";
}
else
{
ArrayList list = collectionCommon.GetArray(str2, infoById.LinkBeginCode, infoById.LinkEndCode);
if (list.Count < 1)
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目链接设置错误!</li>";
}
else
{
this.m_ListContentLinks = list;
if (infoById.UsePaging)
{
this.m_CollectionMessage = this.m_CollectionMessage + "正在分析 <font color='blue'>" + this.m_CollectionItemInfo.ItemName + "</font> 列表分页规则 请稍候...<br/>";
this.DetectionPaging(httpPage, collectionCommon, infoById);
if (!string.IsNullOrEmpty(this.ErrorInfo))
{
return;
}
}
this.m_CollectionMessage = this.m_CollectionMessage + "正在分析 <font color='blue'>" + this.m_CollectionItemInfo.ItemName + "</font> 字段规则 请稍候...<br/>";
this.m_CollectionFieldRuleInfoList = CollectionFieldRules.GetList(this.m_CollectionItemInfo.ItemId);
if (this.m_CollectionFieldRuleInfoList.Count < 1)
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目字段设置没有字段,请进行字段设置!</li>";
}
else
{
string fieldName = "";
StringBuilder builder = new StringBuilder();
foreach (CollectionFieldRuleInfo info2 in this.m_CollectionFieldRuleInfoList)
{
if (info2.RuleType != 2)
{
continue;
}
fieldName = info2.FieldName;
if (builder.Length > 0)
{
if (builder.ToString().Contains("$" + info2.FieldName + "$"))
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目字段" + fieldName + "出现重复,请检查数据库删除多余数据!</li>";
return;
}
builder.Append(info2.FieldName + "$");
}
else
{
builder.Append("$" + info2.FieldName + "$");
}
if (info2.IsNull)
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目没有进行字段设置!</li>";
return;
}
url = new Uri(collectionCommon.DefiniteUrl(list[0].ToString(), this.m_CollectionItemInfo.Url));
httpPage = collectionCommon.GetHttpPage(url, this.m_CollectionItemInfo.CodeType);
if (string.IsNullOrEmpty(collectionCommon.GetInterceptionString(httpPage, info2.BeginCode, info2.EndCode)))
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目字段设置" + fieldName + "采集设置获取失败!</li>";
return;
}
}
this.m_CollectionItemInfo.Detection = true;
CollectionItem.Update(this.m_CollectionItemInfo);
}
}
}
}
}
}
}
}
}
private void DetectionPaging(string constr, CollectionCommon collectionCommon, CollectionListRuleInfo collectionListRuleInfo)
{
CollectionPagingRuleInfo infoById = CollectionPagingRules.GetInfoById(this.m_CollectionItemInfo.ItemId, 0);
switch (infoById.PagingType)
{
case 1:
{
string str = collectionCommon.DefiniteUrl(collectionCommon.GetPaing(constr, infoById.PagingBeginCode, infoById.PagingEndCode), this.m_CollectionItemInfo.Url);
if (!string.IsNullOrEmpty(str))
{
this.m_ArrPaging = "";
this.CountNextLinks(str, constr, collectionCommon, collectionListRuleInfo, infoById);
return;
}
return;
}
case 2:
{
string str2 = infoById.DesignatedUrl.ToLower();
if (!string.IsNullOrEmpty(str2))
{
if (str2.IndexOf("{$id}") < 0)
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目列表指定分页URL字符串没有标签{$ID}!</li>";
return;
}
int scopeBegin = infoById.ScopeBegin;
int scopeEnd = infoById.ScopeEnd;
List<string> list = new List<string>();
if (scopeEnd < scopeBegin)
{
for (int i = scopeBegin; i >= scopeEnd; i--)
{
list.Add(str2.Replace("{$id}", i.ToString()));
}
}
else
{
for (int j = scopeBegin; j <= scopeEnd; j++)
{
list.Add(str2.Replace("{$id}", j.ToString()));
}
}
foreach (string str3 in list)
{
this.AddListContentLinks(str3, collectionCommon, collectionListRuleInfo);
}
break;
}
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目列表指定分页没有填写地址!</li>";
return;
}
case 3:
if (string.IsNullOrEmpty(infoById.PagingUrlList))
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "项目手动分页不能为空!</li>";
return;
}
if (infoById.PagingUrlList.IndexOf("\r\n") <= 0)
{
this.AddListContentLinks(infoById.PagingUrlList, collectionCommon, collectionListRuleInfo);
return;
}
foreach (string str4 in infoById.PagingUrlList.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
{
this.AddListContentLinks(str4, collectionCommon, collectionListRuleInfo);
}
return;
case 4:
{
string str5 = collectionCommon.GetInterceptionString(constr, infoById.PagingBeginCode, infoById.PagingEndCode);
if (!string.IsNullOrEmpty(str5))
{
ArrayList list2 = collectionCommon.GetArray(str5, infoById.LinkBeginCode, infoById.LinkEndCode);
StringBuilder builder = new StringBuilder();
for (int k = 0; k < list2.Count; k++)
{
if (builder.Length > 0)
{
builder.Append("," + collectionCommon.DefiniteUrl(list2[k].ToString(), this.m_CollectionItemInfo.Url));
}
else
{
builder.Append(collectionCommon.DefiniteUrl(list2[k].ToString(), this.m_CollectionItemInfo.Url));
}
}
if (string.IsNullOrEmpty(builder.ToString()))
{
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "没有截取到分页URL链接!</li>";
return;
}
foreach (string str6 in builder.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
{
this.AddListContentLinks(str6, collectionCommon, collectionListRuleInfo);
}
break;
}
this.m_ErrorInfo = "<li>" + this.m_CollectionItemInfo.ItemName + "没有截取到分页URL列表!</li>";
return;
}
default:
return;
}
}
private static string FilterRule(int filterRuleId, CollectionCommon collectionCommon, string testContent)
{
if (filterRuleId > 0)
{
CollectionFilterRuleInfo infoById = CollectionFilterRules.GetInfoById(filterRuleId);
if (!infoById.IsNull)
{
switch (infoById.FilterType)
{
case 1:
testContent = testContent.Replace(infoById.BeginCode, infoById.Replace);
return testContent;
case 2:
testContent = collectionCommon.GetInterceptionString(testContent, infoById.BeginCode, infoById.EndCode);
return testContent;
}
}
}
return testContent;
}
private string GetAllContent(string content, string interceptionContent, CollectionCommon collectionCommon, CollectionFieldRuleInfo collectionFieldRuleInfo)
{
CollectionPagingRuleInfo infoById = CollectionPagingRules.GetInfoById(this.m_CollectionItemInfo.ItemId, 1);
if (!infoById.IsNull)
{
switch (infoById.PagingType)
{
case 1:
{
string str = collectionCommon.GetPaing(content, infoById.PagingBeginCode, infoById.PagingEndCode);
if (!string.IsNullOrEmpty(str))
{
interceptionContent = this.AddPagingContent(collectionCommon.DefiniteUrl(str, this.m_CollectionItemInfo.Url), interceptionContent, collectionCommon, collectionFieldRuleInfo, infoById);
return interceptionContent;
}
return interceptionContent;
}
case 2:
{
string str2 = infoById.DesignatedUrl.ToLower();
if (!string.IsNullOrEmpty(str2))
{
if (str2.IndexOf("{$id}") >= 0)
{
int scopeBegin = infoById.ScopeBegin;
int scopeEnd = infoById.ScopeEnd;
List<string> list = new List<string>();
if (scopeEnd < scopeBegin)
{
for (int i = scopeBegin; i >= scopeEnd; i--)
{
list.Add(str2.Replace("{$id}", i.ToString()));
}
}
else
{
for (int j = scopeBegin; j <= scopeEnd; j++)
{
list.Add(str2.Replace("{$id}", j.ToString()));
}
}
foreach (string str3 in list)
{
interceptionContent = this.AddPagingContent(str3, collectionCommon, collectionFieldRuleInfo, interceptionContent);
}
}
return interceptionContent;
}
return interceptionContent;
}
case 3:
if (!string.IsNullOrEmpty(infoById.PagingUrlList))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -