本文整理汇总了C#中HtmlAgilityPack.SelectSingleNode方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlAgilityPack.SelectSingleNode方法的具体用法?C# HtmlAgilityPack.SelectSingleNode怎么用?C# HtmlAgilityPack.SelectSingleNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack
的用法示例。
在下文中一共展示了HtmlAgilityPack.SelectSingleNode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmailSetting
public EmailSetting(HtmlAgilityPack.HtmlNode emailData)
{
// process the data to get the email settings
EmailAddress = emailData.SelectSingleNode(String.Format(".//input[@name='{0}']", FormInputNames.EmailSettings.EmailAddress))?.GetAttributeValue("value", "");
EmailReceipts = emailData.SelectSingleNode(String.Format(".//input[@name='{0}']", FormInputNames.EmailSettings.EmailRecipientsCheckBox))?.GetAttributeValue("checked", "off") == "checked" ? true : false;
TextReminders = emailData.SelectSingleNode(String.Format(".//input[@name='{0}']", FormInputNames.EmailSettings.TextRemindersCheckBox))?.GetAttributeValue("checked", "off") == "checked" ? true : false;
var select = emailData.SelectSingleNode(String.Format(".//select[@name='{0}']", FormInputNames.EmailSettings.DropDownPreferredLanguage));
Language = select.SelectSingleNode(".//option[@selected='selected']")?.GetAttributeValue("value", "");
}
示例2: TermsConditions
public TermsConditions(HtmlAgilityPack.HtmlNode tc)
{
// process the data to get the security settings
var node = tc.SelectSingleNode("//userlog");
InfoHtml = node.OuterHtml;
InfoText = node.InnerText;
}
示例3: GetDishPrice
public decimal GetDishPrice(HtmlAgilityPack.HtmlNode dishNode)
{
var dishPriceNode = dishNode.SelectSingleNode(".//span[@class='price']");
var dishPrice = dishPriceNode == null ? "0" : dishPriceNode.InnerText.Replace("¥", string.Empty).ClearSiteCode();
decimal priceDecimal = 0;
decimal.TryParse(dishPrice, out priceDecimal);
return priceDecimal;
}
示例4: Planet
/// <summary>
/// parset planetinformationen
/// </summary>
/// <param name="planetNode">Html Knoten, der die Planetinformationen enthält</param>
public Planet(HtmlAgilityPack.HtmlNode planetNode, StringManager strings, Logger logger)
{
logger.Log (LoggingCategories.Parse, "Planet Constructor");
this._name = planetNode.SelectSingleNode (strings.PlanetNameXPath).InnerText;
//Koordinaten auslesen:
string coordsString = planetNode.SelectSingleNode (strings.PlanetCoordsXPath).InnerText;
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match (coordsString, strings.PlanetCoordsRegex);
//Koordinaten Parsen
this._coords.Galaxy = Convert.ToInt32 (match.Groups [1].Value);
this._coords.SunSystem = Convert.ToInt32 (match.Groups [2].Value);
this._coords.Place = Convert.ToInt32 (match.Groups [3].Value);
//Link auslesen:
string linktToPlanet = planetNode.SelectSingleNode (strings.PlanetLinkXPath).Attributes ["href"].Value;
this._id = Utils.StringReplaceToInt32 (Utils.SimpleRegex (linktToPlanet, strings.PlanetIDRegex));
}
示例5: Parse
public static Vehicle Parse(HtmlAgilityPack.HtmlNode htmlData)
{
var vehicleInput = htmlData.SelectSingleNode(".//input[@type='text']/@value");
if (vehicleInput == null)
{
// not a vehicle row
return null;
}
return new Vehicle(htmlData);
}
示例6: GetAttribute
public static string GetAttribute(HtmlAgilityPack.HtmlNode doc, string xpath, string attributeName)
{
string result = string.Empty;
var node = doc.SelectSingleNode(xpath);
if(node != null)
{ result = node.Attributes[attributeName].Value; }
return result;
}
示例7: GetInnerText
public static string GetInnerText(HtmlAgilityPack.HtmlNode doc, string xpath)
{
string result = string.Empty;
var node = doc.SelectSingleNode(xpath);
if(node != null)
{ result = node.InnerText.Trim(); }
return result;
}
示例8: Vehicle
private Vehicle(HtmlAgilityPack.HtmlNode htmlData)
{
// parse the html node to get the info out
string licensePlate = htmlData.SelectSingleNode(".//input[@type='text']/@value")?.GetAttributeValue("value", "");
string vehicleTypeVal = htmlData.SelectSingleNode(".//select/option[@selected='selected']/@value")?.GetAttributeValue("value", "");
var hiddenData = htmlData.SelectNodes(".//input[@type='hidden']");
var hiddenId = hiddenData.Where(input => input.Attributes["name"]?.Value.Contains("VehicleUid") == true)?.First()?.GetAttributeValue("value", "");
var hiddenLicPlate = hiddenData.Where(input => input.Attributes["name"]?.Value.Contains("LicensePlateHiddenField") == true)?.First()?.GetAttributeValue("value", "");
_myType = (VehicleType)int.Parse(vehicleTypeVal);
_myLicensePlate = licensePlate;
_myHiddenLicensePlate = hiddenLicPlate;
_myVehicleId = hiddenId;
WebData = new VehicleWebData(htmlData);
_isFromWebsite = true;
}
示例9: Select
public override dynamic Select(HtmlAgilityPack.HtmlNode element)
{
var node = element.SelectSingleNode(_xpath);
if (node != null)
{
if (HasAttribute())
{
return node.Attributes.Contains(_attribute) ? node.Attributes[_attribute].Value?.Trim() : null;
}
else
{
return node;
}
}
return null;
}
示例10: transformSummaryHTMLNodeIntoCraigslistInfo
/// <summary>
/// Parses data from an HTML node for a listing items to populate most of the data into a craigslistInfo object
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static CraigslistInfo transformSummaryHTMLNodeIntoCraigslistInfo(HtmlAgilityPack.HtmlNode item)
{
CraigslistInfo craigslistInfo = new CraigslistInfo();
//
// the node is a block of HTml that looks like this
//<p class="row" data-latitude="" data-longitude="">
// <span class="ih" id="images:3Ee3K43m25Ne5K95Hecbmc8b000ac1a0e1376.jpg"> </span>
// <span class="itemdate"> Dec 11</span>
// <span class="itemsep"> - </span>
// <a href="http://vancouver.en.craigslist.ca/pml/ctd/3427888027.html">2003 HYUNDAI TIBURON GT</a>
// <span class="itemsep"> - </span>
// <span class="itemph"></span>
// <span class="itempp"> $6595</span>
// <span class="itempn"><font size="-1"> (MISSION)</font></span>
// <span class="itemcg" title="ctd"> <small class="gc"><a href="/ctd/">cars & trucks - by dealer</a></small></span>
// <span class="itempx"> <span class="p"> pic</span></span>
// <br class="c">
// </p>
//
// First of all parse the date : Dec 11
//
// .:TODO:. this is not working and throwing the exception every time - and using the output in jscript breaks the page!
//
string[] formats = { " MMM dd" };
try
{
craigslistInfo.DatePostedReal = DateTime.ParseExact(item.SelectSingleNode("//span[@class='itemdate']").InnerText.Substring(0, formats[0].Length), formats, null, System.Globalization.DateTimeStyles.AssumeUniversal);
}
catch (FormatException)
{
craigslistInfo.DatePostedReal = DateTime.MinValue;
Console.WriteLine("Unable to convert '{0}' to a date.", item.SelectSingleNode("//span[@class='itemdate']").InnerText);
}
//
// Next the Price
//
craigslistInfo.Price = item.SelectSingleNode("//span[@class='itempp']").InnerText.Trim();
craigslistInfo.SaleArea = item.SelectSingleNode("//font").InnerText;
craigslistInfo.LinkURL = item.ChildNodes[7].Attributes["href"].Value;
craigslistInfo.ShortTitle = item.ChildNodes[7].InnerText;
craigslistInfo.Category = item.ChildNodes[17].SelectSingleNode("//a").InnerText;
craigslistInfo.DatePostedParsed = craigslistInfo.DatePostedReal.ToString("dd MMM yyyy HH:mm:ss");
return craigslistInfo;
}
示例11: ProcessGameData
private BasicInfo ProcessGameData(HtmlAgilityPack.HtmlNode game, DateTime gameDate, string webID)
{
// 建立比賽資料,時間以台灣為主
BasicInfo gameInfo = new BasicInfo(this.AllianceID, this.GameType, gameDate, webID);
gameInfo.Away = game.SelectSingleNode("div/div[@class='team visitor']/div[@class='team-capsule']/p[@class='team-name']/span/a").InnerText;
gameInfo.Home = game.SelectSingleNode("div/div[@class='team home']/div[@class='team-capsule']/p[@class='team-name']/span/a").InnerText;
gameInfo.Status = game.SelectSingleNode("div/div[@class='game-header']/div/p").InnerText;
gameInfo.Status = gameInfo.Status.ToLower();
// 取代文字
gameInfo.Status = gameInfo.Status.Replace("halftime", "中場休息");
gameInfo.Status = gameInfo.Status.Replace("half", "中場休息");
gameInfo.Status = gameInfo.Status.Replace("qtr", "");
gameInfo.Status = gameInfo.Status.Replace("1st", "");
gameInfo.Status = gameInfo.Status.Replace("2nd", "");
gameInfo.Status = gameInfo.Status.Replace("3rd", "");
gameInfo.Status = gameInfo.Status.Replace("4th", "");
gameInfo.Status = gameInfo.Status.Replace("ot", "");
gameInfo.Status = gameInfo.Status.Replace("2ot", "");
gameInfo.Status = gameInfo.Status.Replace("of", "");
gameInfo.Status = gameInfo.Status.Replace("end", "結束");
gameInfo.Status = gameInfo.Status.Replace(" ", "");//移除空白字元
gameInfo.Status = gameInfo.Status.Trim();
if (gameInfo.Status == "00:00") gameInfo.Status = "結束";
//目前有顯示的分數欄位
HtmlAgilityPack.HtmlNode scoreHeader = game.SelectSingleNode("div/div[@class='game-header']/ul[@class='score header']");
if (scoreHeader != null)//是否已經有比分
{
string linescoreHeader = game.SelectSingleNode("div/div[@class='game-header']/ul[@class='score header']").InnerText;
if (linescoreHeader.Length > 7)//資料不完整,缺乏前面局數比分 2 3 4 OT OT T
{
//第1個數字才是有顯示的比分
int lossInning = 1;
int.TryParse(linescoreHeader.Substring(0, 1), out lossInning);
if (lossInning > 1)
{
lossInning--;
GetGameScore(gameInfo, lossInning);//無暫存取得遺漏比分
}
}
List<int> FullAwayBoard = new List<int>();//完整比分
List<int> FullHomeBoard = new List<int>();//完整比分
if (this.DownScore.ContainsKey(webID) && !string.IsNullOrEmpty(this.DownScore[webID].Data))
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(this.DownScore[webID].Data);
HtmlAgilityPack.HtmlNodeCollection HomeAway = doc.GetElementbyId("gamepackageTop").SelectNodes("div[@class='line-score clear']/div[@class='line-score-container']/table/tr");
if (HomeAway != null && HomeAway.Count == 3)
{
foreach (HtmlAgilityPack.HtmlNode scores in HomeAway)
{
if (scores.Attributes["class"] != null)//忽略periods
continue;
HtmlAgilityPack.HtmlNodeCollection score = scores.SelectNodes("td");
if (score != null)
{
bool isAway = false;
if (FullAwayBoard.Count == 0)
isAway = true;
int period = score.Count - 1;
for (int i = 1; i < period; i++)//第0個值為隊名
{
string tmpNum = score[i].InnerHtml.Replace("\n", "").Replace("\t", "").Trim();
int tryInt = 0;
int.TryParse(tmpNum, out tryInt);
if (isAway)
FullAwayBoard.Add(tryInt);
else
FullHomeBoard.Add(tryInt);
}
}
}
}
}
//首頁比分計算
foreach (HtmlAgilityPack.HtmlNode numDoc in game.SelectNodes("div/div[@class='team visitor']/ul[@class='score']/li"))
{
int num = 0;
if (int.TryParse(numDoc.InnerText, out num))
{
if (gameInfo.AwayBoard.Count < 4)//沒有OT
gameInfo.AwayBoard.Add(numDoc.InnerText);
else
{
int otDiff = FullAwayBoard.Count - gameInfo.AwayBoard.Count;//OT數差別
if (FullAwayBoard.Count == 0 || otDiff == 0)
gameInfo.AwayBoard.Add(numDoc.InnerText);
else
{
int sum = 0;
for (int i = 0; i < otDiff - 1; i++)
{
//.........这里部分代码省略.........
示例12: VehicleWebData
public VehicleWebData(HtmlAgilityPack.HtmlNode vehicleData)
{
var allInputs = vehicleData.SelectNodes(".//input");
var select = vehicleData.SelectSingleNode(".//select");
LicensePlateTextBox = allInputs.Where(input => input.Attributes["name"]?.Value?.Contains("LicensePlateTextBox") == true).First()?.GetAttributeValue("name", "");
LicensePlateHiddenField = allInputs.Where(input => input.Attributes["name"]?.Value?.Contains("LicensePlateHiddenField") == true).First()?.GetAttributeValue("name", "");
VehicleUidHiddenField = allInputs.Where(input => input.Attributes["name"]?.Value?.Contains("VehicleUidHiddenField") == true).First()?.GetAttributeValue("name", "");
VehicleTypeHiddenField = allInputs.Where(input => input.Attributes["name"]?.Value?.Contains("VehicleTypeUidHiddenField") == true).First()?.GetAttributeValue("name", "");
VehicleTypeDropDown = select?.GetAttributeValue("name", "");
}
示例13: FillCustomer
public ResultType_enum FillCustomer(Customer customer, HtmlAgilityPack.HtmlNode customerNode, InternetRequestEngine internetRequestEngine,
out string message)
{
try
{
message = "";
HtmlAgilityPack.HtmlNode nodeTmp = null;
#region Определение параметров
text = ".//table";
//text += "/tbody"; !!!newBrowser
text += "/tr";
text += "/td[@class=\"descriptTenderTd\"]";
text += "/dl";
text += "/dt";
text += "/a";
nodeTmp = customerNode.SelectSingleNode(text);
// Название заказчика
if (nodeTmp.Attributes.Contains("title"))
customer.Name = Globals.DecodeInternetSymbs(nodeTmp.Attributes["title"].Value.Trim());
// Определение ID 94 и 223 законов
// Есди существует атрибут <href>, значит указана одна ссылка на один закон
LawType_enum lawType = LawType_enum.None;
Regex regex = new Regex(@"http://.*?Id=\d*");
MatchCollection matchColl = null;
if (nodeTmp.Attributes.Contains("href"))
{
matchColl = regex.Matches(nodeTmp.Attributes["href"].Value);
}
else
{
matchColl = regex.Matches(nodeTmp.Attributes["onclick"].Value);
}
foreach (Match match in matchColl)
{
string lawID = GetIDLaw(match.Value, out lawType);
switch (lawType)
{
case (LawType_enum._44_94):
customer.Law_44_94_ID = lawID;
break;
case (LawType_enum._223):
customer.Law_223_ID = lawID;
break;
default:
break;
}
//break;
}
// Уровень организации
text = ".//table";
//text += "/tbody"; !!!newBrowser
text += "/tr";
text += "/td[@class=\"tenderTd\"]";
text += "/dl";
text += "/dt";
nodeTmp = customerNode.SelectSingleNode(text);
CustomerLevel_enum customerLevel = CustomerLevel_enum.None;
if (nodeTmp != null) {
switch(nodeTmp.InnerText.ToLower().Trim()) {
case ("федеральный уровень"):
customerLevel = CustomerLevel_enum.Federal;
break;
case ("уровень субъекта рф"):
customerLevel = CustomerLevel_enum.Subject;
break;
case ("муниципальный уровень"):
customerLevel = CustomerLevel_enum.Municipal;
break;
case ("иное"):
customerLevel = CustomerLevel_enum.Other;
break;
}
}
customer.CustomerLevel = mvm.wc.CustomerLevels.FirstOrDefault(m => m.CustomerLevelCode == customerLevel.ToString());
// ИНН (VATIN)
text = ".//table";
//text += "/tbody"; !!!newBrowser
text += "/tr";
text += "/td[@class=\"descriptTenderTd\"]";
text += "/dl";
text += "/dd[@class=\"nameOrganization\"]";
text += "/span";
HtmlAgilityPack.HtmlNodeCollection collectionVatin = customerNode.SelectNodes(text);
foreach (HtmlAgilityPack.HtmlNode nodeVatin in collectionVatin)
{
int vatinIntPos = nodeVatin.InnerText.IndexOf("ИНН:");
if (vatinIntPos > -1)
{
customer.Vatin = nodeVatin.InnerText.Substring(vatinIntPos + 4, nodeVatin.InnerText.Length - (vatinIntPos + 4)).Trim();
break;
//.........这里部分代码省略.........
示例14: GetMp3Data
private static byte[] GetMp3Data(HtmlAgilityPack.HtmlNode htmlNode)
{
var anchorNode = htmlNode.SelectSingleNode("a");
if (anchorNode != null)
{
var attr = anchorNode.Attributes.FirstOrDefault(x => x.Name == "href");
if (attr != null && attr.Value.ToLower().EndsWith("mp3"))
{
using (var mp3Client = new WebClient())
{
return mp3Client.DownloadData(attr.Value);
}
}
}
return null;
}