本文整理汇总了C#中HtmlAgilityPack.HtmlWeb.GetElementbyId方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlWeb.GetElementbyId方法的具体用法?C# HtmlWeb.GetElementbyId怎么用?C# HtmlWeb.GetElementbyId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlWeb
的用法示例。
在下文中一共展示了HtmlWeb.GetElementbyId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPost
private static Post GetPost(string postId)
{
HtmlDocument document = new HtmlWeb().Load("http://thecodinglove.com/post/" + postId);
HtmlNode someNode = document.GetElementbyId("main");
var post = new Post();
if (someNode != null)
{
var h3 = someNode.SelectNodes("div[2]/div/h3");
var innerText = h3.First().InnerText;
post.Title = innerText;
Console.WriteLine(innerText);
var img = someNode.SelectNodes("div[2]/div[2]/p/p/img");
var src = img.First().Attributes["src"].Value;
post.ImageUrl = src;
Console.WriteLine("src: " + src);
}
return post;
}
示例2: ReadPower
public void ReadPower()
{
try {
var doc = new HtmlWeb().Load(_currentIP);
if (doc == null) {
_logger.Log("The page was not found!", LogType.ERROR);
_ipFinder.FindIP();
ReadingCancelled(this, new EventArgs());
return;
}
var element = doc.GetElementbyId("Power");
if (element == null) {
_logger.Log("The \"Power\" element was not found!", LogType.ERROR);
ReadingCancelled(this, new EventArgs());
return;
}
var power = element.InnerHtml;
if (String.IsNullOrEmpty(power)) {
_logger.Log("Power value is empty!", LogType.ERROR);
ReadingCancelled(this, new EventArgs());
return;
}
power = power.Trim();
if (power.ToLowerInvariant().Contains("kw")) {
power = Regex.Replace(power, @" .*", "");
power = Regex.Replace(power, @"\.", ",");
float kwPower;
if (float.TryParse(power, out kwPower)) {
kwPower *= 1000;
PowerChanged(new PowerChangedEventArgs((int) kwPower));
} else {
Logger.Instance.Value.Log("Cannot convert the power to float - " + power, LogType.ERROR);
}
} else {
power = Regex.Replace(power, @"[^\d]", "");
int intPower;
if (int.TryParse(power, out intPower)) {
PowerChanged(new PowerChangedEventArgs(intPower));
} else {
Logger.Instance.Value.Log("Cannot convert the power to int - " + power, LogType.ERROR);
}
}
} catch (Exception e) {
_logger.Log("Exception occured: " + e.Message + Environment.NewLine + e.StackTrace, LogType.ERROR);
_ipFinder.FindIP();
ReadingCancelled(this, new EventArgs());
}
}