本文整理汇总了C#中IHtmlElement.FindFirst方法的典型用法代码示例。如果您正苦于以下问题:C# IHtmlElement.FindFirst方法的具体用法?C# IHtmlElement.FindFirst怎么用?C# IHtmlElement.FindFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHtmlElement
的用法示例。
在下文中一共展示了IHtmlElement.FindFirst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TableEntity
public TableEntity(IHtmlElement tableElement)
{
var head = tableElement.FindFirst("thead");
this.THead = new THeadEntity(head);
var headTrList = head.Find("tr");
foreach (var tr in headTrList)
{
var trEntity = new TrEntity(tr);
var tdList = tr.Find("td").ToList();
foreach (var td in tdList)
{
trEntity.TdList.Add(new TdEntity(td) { Text = td.InnerText() });
}
this.THead.TrList.Add(trEntity);
}
var body = tableElement.FindFirst("tbody");
this.TBody = new TBodyEntity(body);
var bodyTrList = body.Find("tr");
foreach (var tr in bodyTrList)
{
var trEntity = new TrEntity(tr);
var tdList = tr.Find("td").ToList();
foreach (var td in tdList)
{
trEntity.TdList.Add(new TdEntity(td) { Text = td.InnerText() });
}
this.TBody.TrList.Add(trEntity);
}
}
示例2: BuildEntity
private ExamItem BuildEntity(int moduleId, IHtmlElement item)
{
string selector = @"td[width]";
if (false == item.Exists(selector)) { return null; }
var id_element = item.FindFirst(selector);
if (id_element == null) { return null; }
try
{
var match = Regex.Match(id_element.InnerText(), @"\d+");
int id = Convert.ToInt32(match.Value.ToString().Trim());
string title = id_element.Parent().FindFirst(@".MsoNormal>span").InnerText().Trim().RemoveHtml().RemoveHtmlEncode();
string answer = item.FindFirst("#answer").InnerText().Trim();
string strExamType = item.FindFirst(".st_title").InnerText();
string examType = Regex.Match(strExamType, @"(?<=、).*").Value.Trim();
if (answer.StartsWith("答案:"))
{
answer = answer.Substring(3).Trim();
}
var itemType = ItemTypeService.GetByText(examType);
if (itemType == null)
{
logger.Info(string.Format("未匹配的题目类别[{0}],ExamId=[{1}]", examType, id));
}
var model = new ExamItem()
{
Id = id,
Title = title,
Answer = answer,
OriginalHtml = item.InnerHtml(),
Module_Id = moduleId,
ItemType = itemType != null ? itemType.Id : 0,
CreateTime = DateTime.Now,
DelFlag = false
};
return model;
}
catch (Exception ex)
{
WriteLog(item.ToString(), ex.Message);
throw;
}
}
示例3: BuildEntity
private ExamItem BuildEntity(int moduleId, IHtmlElement item)
{
try
{
var id_element = item.FindFirst(@"tr[valign]>td");
var match = Regex.Match(id_element.InnerText(), @"\d+");
int id = Convert.ToInt32(match.Value.Trim());
string title = id_element.NextElement().InnerText().Trim().RemoveHtml().RemoveHtmlEncode();
string answer = item.FindFirst("div[id]").InnerText().Trim().RemoveHtmlEncode();
string examType = item.PreviousElement().Descendants("td")
.ElementAt(1)
.InnerText().Trim().RemoveHtml().RemoveHtmlEncode();
if (answer.StartsWith("答案:"))
{
answer = answer.Substring(3).Trim();
}
var itemType = ItemTypeService.GetByText(examType);
if (itemType == null)
{
logger.Info(string.Format("未匹配的题目类别[{0}],ExamId=[{1}]", examType, id));
}
var model = new ExamItem()
{
Id = id,
Title = title,
Answer = answer,
OriginalHtml = item.InnerHtml(),
Module_Id = moduleId,
ItemType = itemType != null ? itemType.Id : 0,
CreateTime = DateTime.Now,
DelFlag = false
};
return model;
}
catch (Exception ex)
{
WriteLog(item.ToString(), ex.Message);
throw;
}
}