本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.GetElementbyId方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.GetElementbyId方法的具体用法?C# HtmlDocument.GetElementbyId怎么用?C# HtmlDocument.GetElementbyId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.GetElementbyId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadHtmlTemplate
private void LoadHtmlTemplate()
{
this.document = new HtmlDocument();
this.document.Load( Assembly.GetExecutingAssembly().GetManifestResourceStream(HtmlTemplate) );
this.table = new HtmlNodeCollection(document.GetElementbyId(LogEventTableId));
}
示例2: GetBrand
public void GetBrand(WebParserModel md)
{
WebRequest wr = WebRequest.Create("http://www.komus.ru/product/"+md.Referense.Substring(5)+"/#features");
wr.Proxy=null;
var resp = wr.GetResponse();
var result = "";
using(StreamReader sr = new StreamReader(resp.GetResponseStream(),Encoding.UTF8)){
result = sr.ReadToEnd();
}
HtmlDocument html = new HtmlDocument();
html.LoadHtml(result);
var outer = html.GetElementbyId("breadcrumb_js");
var wrapper = outer.NextSibling.NextSibling.NextSibling.NextSibling;
var bigImg = wrapper.ChildNodes.FindFirst("img").Attributes["src"].Value;
var cat="";
md.Title=wrapper.ChildNodes[3].ChildNodes.FindFirst("h1").InnerText.Trim(); // title
md.ImageUrl = bigImg; // img url
outer = html.GetElementbyId("tabs--content-item-features");
var tableLinesCount = outer.ChildNodes.FindFirst("table").Elements("tr").Last().ChildNodes[3].InnerText.Trim();
if (tableLinesCount == " ")
{
cat = outer.ChildNodes.FindFirst("table").Elements("tr").Last().PreviousSibling.PreviousSibling.ChildNodes[3].InnerHtml;
md.Brand = Regex.Match(cat, @"\w+(?=(</span>))").Value;
}
else {
cat = tableLinesCount;
md.Brand = cat;
}
//ViewBag.outer = bigImg;
}
示例3: GetMyTeamTransferValues
/// <returns>Dictionary mapping player id to transfer value in 100,000's</returns>
public Dictionary<int,int> GetMyTeamTransferValues()
{
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(_transfersPageHtmlString);
//var body = htmlDoc.GetElementbyId("ismTeamDisplayGraphical");
//var ismPitch = body.SelectSingleNode("//div[@class='ismPitch']");
//var players = ismPitch.SelectNodes("//div[@class='ismPlayerContainer']");
var result = new Dictionary<int, int>();
for (int i = 0; i < 15; i++)
{
string playerIdStr = htmlDoc.GetElementbyId(string.Format("id_pick_formset-{0}-element", i)).GetAttributeValue("value", "");
int playerId = int.Parse(playerIdStr);
string salePriceStr = htmlDoc.GetElementbyId(string.Format("id_pick_formset-{0}-selling_price", i)).GetAttributeValue("value", "");
int salePrice = int.Parse(salePriceStr);
result.Add(playerId, salePrice);
}
/*foreach (var player in players)
{
string playerIdStr = player.SelectSingleNode("//a[@class='ismViewProfile']").GetAttributeValue("href",""); // string in form "#<id>"
int playerId = int.Parse(playerIdStr.TrimStart('#'));
string salePriceStr = player.SelectSingleNode("//span[@class='ismPitchStat']").InnerText; // string in form "£<sell price>"
decimal salePrice = decimal.Parse(salePriceStr.TrimStart('£'));
result.Add(playerId, salePrice);
}*/
return result;
}
示例4: DefineTheHtml_File
public void DefineTheHtml_File(string filePath)
{
using (StreamReader reader = new StreamReader(filePath, Encoding.Default)) //Unicode-, ASCII-, UTF8-,UTF7-,UTF32-,BigEndianUnicode-
{
var html = new HtmlDocument();
var stringHtml = reader.ReadToEnd();
html.LoadHtml(stringHtml);
var doc = html.GetElementbyId("initial_list"); //results <- поиск
if (doc == null) // if true ? html from search list : html from my audio list
{
doc = html.GetElementbyId("results");
var arr = doc.ChildNodes.Where(x => x.Name == "div").ToArray();
CreateCollectionFromSearch(arr);
}
if (doc == null)
throw new Exception("Не поддерживаемый html");
var arrayHtmlNode = doc.ChildNodes.Where(x => x.InnerHtml != "").ToArray();
CreateCollectionSongsMyAudio(arrayHtmlNode);
}
}
示例5: ExecuteAsync
public override async Task ExecuteAsync(Update update, Dictionary<string, string> parsedMessage)
{
var response = await GetHtml();
string responseString;
using (var tr = new StreamReader(response))
{
responseString = tr.ReadToEnd();
}
var startIndex = responseString.IndexOf("+=") + 2;
var endIndex = responseString.IndexOf(";\ndocument");
var tempStr = responseString.Substring(startIndex, endIndex - startIndex);
var partsList = tempStr.Split('+').Select(x => x.Trim()).ToList();
tempStr = "";
// remove ' symbols
partsList.ForEach(x => tempStr += x.Substring(1, x.Length - 2));
HtmlDocument document = new HtmlDocument();
document.LoadHtml(tempStr);
var quote = document.GetElementbyId(QuoteTagId);
var rating = document.GetElementbyId(RatingTagId);
var result = rating.InnerText + Environment.NewLine + quote.InnerHtml.Replace(QuoteLineBreak, Environment.NewLine);
await Bot.SendTextMessageAsync(update.Message.Chat.Id, HttpUtility.HtmlDecode(result), false, false, update.Message.MessageId);
}
示例6: GetStockBonus
public IEnumerable<IStockBonus> GetStockBonus(string stockCode)
{
string url = string.Format(@"http://vip.stock.finance.sina.com.cn/corp/go.php/vISSUE_ShareBonus/stockid/{0}.phtml", stockCode);
string pageHtml = PageReader.GetPageSource(url);
if (string.IsNullOrEmpty(pageHtml))
return null;
var htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(pageHtml);
HtmlNode titleNode = htmlDocument.DocumentNode.SelectSingleNode("//title");
//string name = titleNode.InnerText.Substring(0, titleNode.InnerText.IndexOf("("));
HtmlNode nodeSharebonus_1 = htmlDocument.GetElementbyId("sharebonus_1");
HtmlNode nodeSharebonus_2 = htmlDocument.GetElementbyId("sharebonus_2");
List<IStockBonus> lstStockBonus = new List<IStockBonus>();
var lstNodes1 = nodeSharebonus_1.SelectNodes("tbody/tr");
foreach (var item in lstNodes1)
{
var nodes = item.SelectNodes("td");
string urlDetails = string.Format(@"http://vip.stock.finance.sina.com.cn/{0}", item.SelectSingleNode("td/a").Attributes["href"].Value);
var stockBonus = new StockBonus()
{
//Code = stockCode,
//ShortName = name,
DateOfDeclaration = DateTime.Parse(nodes[0].InnerText),// 公告日期
Type = BounsType.ProfitSharing,// 分红类型
ExdividendDate = DateTime.Parse(nodes[5].InnerText),// 除权除息日
RegisterDate = DateTime.Parse(nodes[6].InnerText), // 股权登记日
};
StockBonusDetailsParser(urlDetails, ref stockBonus);
lstStockBonus.Add(stockBonus);
}
var lstNodes2 = nodeSharebonus_2.SelectNodes("tbody/tr");
foreach (var item in lstNodes2)
{
var nodes = item.SelectNodes("td");
string urlDetails = string.Format(@"http://vip.stock.finance.sina.com.cn/{0}", item.SelectSingleNode("td/a").Attributes["href"].Value);
var stockBonus = new StockBonus()
{
//Code = stockCode,
//ShortName = name,
DateOfDeclaration = DateTime.Parse(nodes[0].InnerText),// 公告日期
Type = BounsType.StockOption,// 配股类型
ExdividendDate = DateTime.Parse(nodes[4].InnerText),// 除权除息日
RegisterDate = DateTime.Parse(nodes[5].InnerText), // 股权登记日
};
StockBonusDetailsParser(urlDetails, ref stockBonus);
lstStockBonus.Add(stockBonus);
}
return lstStockBonus;
}
示例7: DoSingleContent
private void DoSingleContent(string url)
{
// url = "http://xidong.net/File001/File_8766.html";
string content = fh.GetWebContents(url, Encoding.UTF8);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(content);
HtmlNode root = doc.DocumentNode;
string title = doc.GetElementbyId("xdintrobg").SelectSingleNode("h1").InnerText;
Console.WriteLine(title);
string contMain = Helper.String.StringHelper.SubStr(content, "<script type=\"text/javascript\" src=\"http://src.xidong.net/js/select.js\"></script>",
"<div id=\"ggad-content-bottom\">"
);
contMain = contMain.Replace("<!-- google_ad_section_start -->", "");
contMain = contMain.Replace("<!-- google_ad_section_end -->", "");
Regex reg = new Regex("(?i)(?s)<script.*?</script>");
contMain = reg.Replace(contMain, "");
Console.WriteLine(contMain);
string links = "";
Dictionary<string, string> linkList = new Dictionary<string, string>();
HtmlNode node = doc.GetElementbyId("emulelink");
for (int i = 1; i <= 50; i++)
{
node = doc.GetElementbyId("emulelink");
node = node.SelectSingleNode("table[1]/tr[" + i + "]");
if (node != null)
{
if (node.InnerText.IndexOf("用迅雷、eMule等软件下载") > -1) continue;
HtmlNode hn1 = node.SelectSingleNode("td[1]/a[1]");
if (hn1 != null)
{
string rs = "";
string href = hn1.Attributes["href"].Value;
string text = hn1.InnerText;
string size = "0";
rs += text + "$$";
HtmlNode hn2 = node.SelectSingleNode("td[2]");
if (hn2 != null)
{
size = hn2.InnerText;
}
rs += size + "$$";
rs += href;
Console.WriteLine(rs);
}
}
}
// Console.WriteLine(content);
}
示例8: Parse
public Image Parse(HtmlDocument d, string url)
{
doc = d;
HtmlNode podright = doc.GetElementbyId("pod_right");
foreach (HtmlNode childNode in podright.ChildNodes)
{
if (childNode.GetAttributeValue("class", string.Empty) == "publication_time")
{
string dateText = childNode.InnerText;
DateTime date = DateTime.Parse(dateText);
image.Date = date.Date;
}
}
HtmlNode head = doc.GetElementbyId("page_head");
foreach (HtmlNode childNode in head.ChildNodes)
{
if (childNode.Name == "h1")
{
string title = childNode.InnerText;
image.Title = title;
}
}
GetDownloadLink();
HtmlNode primary =
doc.DocumentNode.Descendants().First(
x => x.GetAttributeValue("class", string.Empty) == "primary_photo" && x.Name == "div");
HtmlNode prevLink = primary.ChildNodes.First(x => x.Name == "a");
string prevLinkRef = prevLink.GetAttributeValue("href", string.Empty);
image.PreviousDayUrl = "http://photography.nationalgeographic.com" + prevLinkRef;
HtmlNode potdImage = prevLink.ChildNodes.First(x => x.Name == "img");
image.Description = potdImage.GetAttributeValue("alt", string.Empty);
image.Url = potdImage.GetAttributeValue("src", string.Empty);
GetPhotographer();
return image;
}
示例9: Parse
public IDictionary<string, string> Parse(string html)
{
var doc = new HtmlDocument
{
OptionUseIdAttribute = true,
OptionFixNestedTags = true
};
doc.LoadHtml(html);
var fundamentals = new Dictionary<string, string>();
foreach (var row in doc.GetElementbyId("currentValuationTable").Element("tbody").Elements("tr"))
{
if (row.Element("th") == null)
continue;
var fundamental = HtmlEntity.DeEntitize(row.Element("th").InnerText);
var value = HtmlEntity.DeEntitize(row.Elements("td").First().InnerText);
Log.DebugFormat("Found: {0} = {1}", fundamental, value);
fundamentals.Add(fundamental, value);
}
return fundamentals;
}
示例10: OtoMotoResultPage
public OtoMotoResultPage(string rawResponse)
{
// TODO: Complete member initialization
this.rawResponse = rawResponse;
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(rawResponse);
htmlDoc.OptionFixNestedTags = true;
HtmlNode node = htmlDoc.GetElementbyId("mainRightOM");
Console.WriteLine(node.InnerHtml);
if (htmlDoc.ParseErrors != null)
{
// Handle any parse errors as required
Console.WriteLine("Errors ;(");
}
else
{
Console.WriteLine("No errors, hurray!");
}
HtmlNode n = node.SelectSingleNode("div[@id='programList']");
BuildCarList();
//BuildLinkList();
//BuildNextLink();
//BuildPreviousLink();
}
示例11: Parse
public static IEnumerable<KillStatistic> Parse(string htmlPage)
{
HtmlDocument page = new HtmlDocument();
page.LoadHtml(htmlPage);
var tables = page.GetElementbyId("killstatistics").Descendants("table");
if (tables.Count() < 2) throw new ArgumentException("Page format not correct");
var statsTable = tables.Last();
var tableRows = statsTable.Descendants("tr").Skip(2);
IList<KillStatistic> extractedStatistics = new List<KillStatistic>();
foreach(var row in tableRows)
{
var columns = row.Descendants("td");
KillStatistic stat = new KillStatistic { Monster = columns.First().InnerText.Replace(" ", ""), Date = DateTime.Now.AddDays(-1) };
stat.KilledPlayers = Convert.ToInt32(columns.ElementAt(1).InnerText.Replace(" ", ""));
stat.KilledByPlayers = Convert.ToInt32(columns.ElementAt(2).InnerText.Replace(" ", ""));
extractedStatistics.Add(stat);
}
return extractedStatistics;
}
示例12: GetFixtures
public IEnumerable<Fixture> GetFixtures()
{
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(ReadHtml());
var calHolder = doc.GetElementbyId("CalendarHolder");
var rows = calHolder.ChildNodes;
foreach (var row in rows)
{
foreach (var column in row.ChildNodes)
{
string currentHtml = column.InnerHtml;
while (currentHtml.Contains("a href"))
{
yield return GetFixture(currentHtml);
int href = currentHtml.IndexOf("a href");
currentHtml = currentHtml.Substring(href + 1);
}
}
}
yield break;
}
示例13: WriteContent
private void WriteContent(HtmlDocument doc)
{
HtmlNode bodyContent = doc.GetElementbyId("bodyContent");
var heading = doc.CreateElement("h1");
heading.InnerHtml = "Heading";
bodyContent.AppendChild(heading);
HtmlNode table = bodyContent.CreateElement("table");
table.CreateAttributeWithValue("class", "table table-striped table-bordered");
var tableHead = table.CreateElement("thead");
var headerRow = tableHead.CreateElement("tr");
headerRow.CreateElementWithHtml("td", "First");
headerRow.CreateElementWithHtml("td", "Second");
headerRow.CreateElementWithHtml("td", "Third");
headerRow.CreateElementWithHtml("td", "Fourth");
headerRow.CreateElementWithHtml("td", "Fifth");
HtmlNode tableBody = table.CreateElement("tbody");
const string text = "Fi fa fo fum fi fa fo fum fi fa fo fum fi fa fo fum";
for (int i = 0; i < 10; i++)
{
HtmlNode bodyRow = tableBody.CreateElement("tr");
bodyRow.CreateElementWithHtml("td", i + " first " + text);
bodyRow.CreateElementWithHtml("td", i + " second " + text);
bodyRow.CreateElementWithHtml("td", i + " third " + text);
bodyRow.CreateElementWithHtml("td", i + " fourth " + text);
bodyRow.CreateElementWithHtml("td", i + " fifth " + text);
}
}
示例14: CasAuthenticate
private void CasAuthenticate(Site site, ref CookieCollection cookies, ref HtmlDocument document)
{
// read the parameters we need to know
var form = document.GetElementbyId("fm1");
var hidden = document.DocumentNode.Descendants("input").Where(a => a.Attributes["type"].Value == "hidden");
var parameters = new StringBuilder();
foreach (var p in hidden)
{
parameters.Append(string.Format("{0}={1}&", p.Attributes["name"].Value, p.Attributes["value"].Value));
}
var action = form.Attributes["action"];
var username = ConfigurationSettings.AppSettings["username"];
var password = ConfigurationSettings.AppSettings["password"];
parameters.Append(string.Format("{0}={1}&", "username", username));
parameters.Append(string.Format("{0}={1}", "password", password));
// location to redirect back to the application
var redirectLocation = string.Empty;
MakeWebCallWithParameters("https://cas.ucdavis.edu:8443" + action.Value, parameters.ToString(), ref cookies, out redirectLocation);
// get the ticket
var ticketUrl = string.Format("https://cas.ucdavis.edu:8443/cas/login?service={0}", redirectLocation);
var location = string.Empty;
ErrorTypes errorType;
MakeWebCall(ticketUrl, false, ref cookies, ref document, out location, out errorType);
// get the aspx auth id
var nothing = string.Empty;
MakeWebCall(location, false, ref cookies, ref document, out nothing, out errorType);
}
示例15: GetEmptyForm
private static HtmlNode GetEmptyForm()
{
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml("<form id='f' action='/'></form>");
var node = htmlDoc.GetElementbyId("f");
return node;
}