public HtmlNode GetElementByProperty(IEnumerable <HtmlNode> nodes, string propertyName, string propertyValue) { HtmlNode n = null; foreach (HtmlNode node in nodes) { HtmlAttributeCollection attributes = node.Attributes; if (attributes.Count > 0) { foreach (HtmlAttribute att in attributes) { if (att.Name != null && att.Name.Equals(propertyName) && att.Value.Equals(propertyValue)) { n = node; break; } } if (n != null) { break; } } } return(n); }
public LoginXPXB() { InitializeComponent(); ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); loginUrl = BbQuery.BbLoginUrlNative; loginUrl += "/?action=relogin"; loginDoc = getLoginDoc(loginUrl); doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(loginDoc); var forms = doc.DocumentNode.Descendants("FORM");//.Where(node => node.Name == "login"); foreach (var f in forms) { HtmlAttributeCollection atts = f.Attributes; foreach (HtmlAttribute h in atts) { Debug.WriteLine(h.Name + " = " + h.Value); } Debug.WriteLine("form descs inputs " + f.Descendants("INPUT").Count().ToString()); } var inputs = doc.DocumentNode.Descendants("INPUT"); foreach (var f in inputs) { HtmlAttributeCollection atts = f.Attributes; foreach (HtmlAttribute h in atts) { Debug.WriteLine(h.Name + " = " + h.Value); } } }
private void TruncateTag(HtmlNode node, string tagName) { HtmlAttributeCollection attributes = node.Attributes; while (attributes.Count > 0) { AddError(Constants.ERROR_ATTRIBUTE_NOT_IN_POLICY, HtmlEntityEncoder.HtmlEntityEncode(tagName), HtmlEntityEncoder.HtmlEntityEncode(attributes[0].Name), HtmlEntityEncoder.HtmlEntityEncode(attributes[0].Value)); node.Attributes.Remove(attributes[0].Name); } HtmlNodeCollection childNodes = node.ChildNodes; int j = 0; int length = childNodes.Count; for (int i = 0; i < length; i++) { HtmlNode nodeToRemove = childNodes[j]; if (nodeToRemove.NodeType != HtmlNodeType.Text) { node.RemoveChild(nodeToRemove); } else { j++; } } }
public void GetContent() { if (docPageParse != null) { HtmlNodeCollection pageNodes = docPageParse.DocumentNode.SelectNodes("//tr"); if (pageNodes != null) { foreach (var item in pageNodes) { HtmlAttributeCollection str = item.Attributes; foreach (var item1 in str) { if (item1.Name == "style") { if (item1.Value == "cursor:pointer;") { VRXParsePage record = new VRXParsePage((item.Id).Replace("td", "")); SaveRecord(record.saveRecord); } } } } } else { SaveError("Content is not null (NOT VIP) " + pageParse); } } }
//________________________________________________________________________________________________________ //第二部分实验 (模块1:根据模板抽取信息) private void divide_Click(object sender, EventArgs e) //得到模板节点 { HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); String txt = this.Domtext.Text; doc.LoadHtml(txt); HtmlNode node = doc.DocumentNode.FirstChild; HtmlAttributeCollection attrcollection = node.Attributes; String tag = node.Name; HtmlAttributeCollection attrs = node.Attributes; foreach (var item in attrs) { Console.WriteLine(item.Name + " : " + item.Value); //提取节点的属性集合 } this.Domtext.Text = tag + " " + node.HasChildNodes; Console.WriteLine("文本信息: " + node.InnerText); /* foreach (HtmlNode link in doc.DocumentNode.ChildNodes) * { * // this.Domtext.Text=link.InnerText; * // Console.Out.WriteLine(link.InnerText); * * } */ }
public void HtmlAttributeCollectionConstructorTest() { HtmlElement element = new HtmlElement("root"); HtmlAttributeCollection target = new HtmlAttributeCollection(element); StringAssert.Equals(target.HtmlElement.Name, "root"); }
private static void TryRemoveTagAttribute(HtmlAttributeCollection atts) { for (int i = atts.Count - 1; i >= 0; i--) { var item = atts[i]; if (DefaultAllowedAttributes.Contains(item.Name) == false) { item.Remove(); continue; } if (item.Value.Contains("&{")) { item.Remove(); continue; } if (DefaultUriAttributes.Contains(item.Name)) { if (TryRemoveSchemes(item)) { continue; } } if (item.Name.ToLower() == "style") { TryRemoveStyle(item); } } }
public bool Start(NBoilerpipeContentHandler instance, string localName, HtmlAttributeCollection atts) { string sizeAttr = atts ["size"].Value; if (sizeAttr != null) { Matcher m = CommonTagActions.PAT_FONT_SIZE.Matcher(sizeAttr); if (m.Matches()) { string rel = m.Group(1); int val = System.Convert.ToInt32(m.Group(2)); int size; if (rel.Length == 0) { // absolute size = val; } else { // relative int?prevSize; if (instance.fontSizeStack.IsEmpty()) { prevSize = 3; } else { prevSize = 3; foreach (int?s in instance.fontSizeStack) { if (s != null) { prevSize = s; break; } } } if (rel[0] == '+') { size = (int)prevSize + val; } else { size = (int)prevSize - val; } } instance.fontSizeStack.Add(0, size); } else { instance.fontSizeStack.Add(0, null); } } else { instance.fontSizeStack.Add(0, null); } return(false); }
private void ReadEventDetails(HtmlDocument doc) { // Read event table for event details //HtmlNode eventTable = doc.DocumentNode.SelectNodes(eventTableTag)[0]; try { foreach (HtmlNode eventTable in doc.DocumentNode.SelectNodes(eventTableTag)) { HtmlAttributeCollection attributes = eventTable.Attributes; foreach (HtmlAttribute dateAttribute in attributes.AttributesWithName(dateTag)) { dateString = dateAttribute.Value; } foreach (HtmlAttribute eventAttribute in attributes.AttributesWithName(eventTag)) { eventName = eventAttribute.Value; } foreach (HtmlAttribute betTypeAttribute in attributes.AttributesWithName(betTag)) { betType = betTypeAttribute.Value; } foreach (HtmlAttribute sportAttribute in attributes.AttributesWithName(sportTag)) { sport = sportAttribute.Value; } foreach (HtmlAttribute sportBracketAttribute in attributes.AttributesWithName(sportBracketTag)) { sportBracket = sportBracketAttribute.Value; } } } catch { } if (dateString != "") { try { eventTime = Convert.ToDateTime(dateString); if (eventTime < DateTime.Now) { inPlay = true; } } catch { } timeToEvent = eventTime - DateTime.Now; } }
private void LoadInOdds(HtmlDocument doc) { List <string> bookieCodesList = new List <string>(); HtmlNode headerRow = doc.DocumentNode.SelectNodes(eventTableHeaderTag)[0]; if (headerRow != null) { foreach (HtmlNode cell in headerRow.SelectNodes("th|td")) { HtmlAttributeCollection attributes = cell.Attributes; foreach (HtmlAttribute bookieCode in attributes.AttributesWithName(bookieTag)) { // If bookie code is not already in the list if (!bookieCodesList.Contains(bookieCode.Value)) { bookieCodesList.Add(bookieCode.Value); } } } } HtmlNodeCollection eventRows = doc.DocumentNode.SelectNodes(eventTableRowTag); foreach (HtmlNode eventRow in eventRows) { string name = ""; List <string> oddsList = new List <string>(); HtmlAttributeCollection attributes = eventRow.Attributes; foreach (HtmlAttribute resultName in attributes.AttributesWithName(resultTag)) { name = resultName.Value; } foreach (HtmlNode cell in eventRow.SelectNodes("th|td")) { attributes = cell.Attributes; bool isNoBet = (cell.Attributes.Contains("class") && cell.Attributes["class"].Value.Contains(noBetTag)); if (!isNoBet) { foreach (HtmlAttribute odds in attributes.AttributesWithName(oddsTag)) { oddsList.Add(odds.Value); } } else { oddsList.Add("0"); } } results.Add(new Result(name, bookieCodesList, oddsList, bookmakers)); } }
protected override void RenderBeginTag(string tagName, HtmlAttributeCollection attributes) { var ctx = CurrentContext; ctx.Document.AddStyleAttribute("white-space", "nowrap"); ctx.Document.RenderBeginTag("span"); base.RenderBeginTag(tagName, attributes); }
/// <summary> /// 删除节点上所有的属性 /// </summary> /// <param name="node"></param> public static void RemoveAttributes(this HtmlNode node) { HtmlAttributeCollection attrs = node.Attributes; for (var i = 0; i < attrs.Count; i++) { node.Attributes.Remove(attrs[i]); } }
private void TagContentSearch_Click(object sender, RoutedEventArgs e) { string TagName = GUITagBox.Text; string[] Attributes = GUITagAttributeBox.Text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);; List <HtmlNode> acceptedNodes = new List <HtmlNode>(); // those among matchingNodes that have all required attributes FolderArea.Text = ""; foreach (string filePath in LocalFolderFiles) { string fileContents = File.ReadAllText(filePath); HtmlAgilityPack.HtmlDocument theHTML = new HtmlDocument(); theHTML.LoadHtml(fileContents); IEnumerable <HtmlNode> matchingNodes = theHTML.DocumentNode.Descendants(TagName); foreach (var matchingNode in matchingNodes) { HtmlAttributeCollection matchingAttrs = matchingNode.Attributes; bool AcceptThisNode = true; foreach (string attribute in Attributes) { HtmlAttribute attr = matchingAttrs[0]; int Number = matchingAttrs.Where(x => x.Name == attribute).Count(); if (Number == 0) { //this matchingNode did not make it - go to next outer loop AcceptThisNode = false; break; } } if (AcceptThisNode) { if (matchingNode.InnerHtml != "" && matchingNode.InnerHtml != null) { acceptedNodes.Add(matchingNode); } } } } if (acceptedNodes.Count() == 0) { FolderArea.Text = "No matching tags were found."; } else { foreach (HtmlNode node in acceptedNodes) { FolderArea.Text += node.InnerHtml; } } }//end fn
internal static JObject NodeAttributesToJson(HtmlAttributeCollection attributeCollection) { var json = new JObject(); foreach (var attribute in attributeCollection) { json.Add(attribute.Name, attribute.Value); } return(json); }
public static Hashtable fromSetting(string html) { Hashtable ht = new Hashtable(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); string data = null; string cUrl = null; foreach (HtmlNode form in doc.DocumentNode.SelectNodes("//form")) { cUrl = form.Attributes["action"].Value; ht["url"] = cUrl; //Console.WriteLine("Found: " + form.Attributes["action"].Value); //HtmlAttributeCollection attrs = form.Attributes; //// Console.Write(attrs.Count.ToString()); //Console.WriteLine("Found: " + form.ChildAttributes("action")); foreach (HtmlNode row in form.SelectNodes("//input"))//这里只是遍历所有的INPUT元素 { HtmlAttributeCollection input = row.Attributes; Console.WriteLine("row"); string cInputName = null; string cInputValue = null; foreach (var item in input)//这里只是遍历一个元素所有属性 { if (item.Name.ToString().ToLower().Equals("name")) { cInputName = item.Value; } if (item.Name.ToString().ToLower().Equals("value")) { cInputValue = item.Value; } } if (cInputName == null) { continue; } if (cInputName.Equals("key")) { ht["key"] = cInputValue; } ; data += cInputName + "=" + cInputValue; data += "&"; } } if (data != null) { ht["data"] = data; } return(ht); }
public static void AddAttribute(HtmlAttributeCollection atributos, string key, string value, FieldTypes fieldType) { if (atributos.Contains(key)) { atributos[key].Value += ", " + value; } else { atributos.Add(key, value); } }
/// <summary> /// Gets the value of an HTML attribute safely from an HTMLAttributeCollection /// </summary> /// <param name="p_hacCollection"></param> /// <param name="p_strItem"></param> /// <returns></returns> private static string GetHtmlAttributeValue(HtmlAttributeCollection p_hacCollection, string p_strItem) { if (p_hacCollection.Contains(p_strItem)) { return(((HtmlAttribute)p_hacCollection[p_strItem]).Value); } else { return(""); } }
public string ExtractQueryHashScriptLink() { HtmlNode link = _documentNode.QuerySelector("[href*=\"" + QueryHashSource + "\"]"); HtmlAttributeCollection attributes = link.Attributes; HtmlAttribute href = attributes.FirstOrDefault(attr => attr.Name == "href"); string scriptSourceRelative = href.Value; string scriptSourceAbsolute = Utility.BaseUrl + scriptSourceRelative; return(scriptSourceAbsolute); }
private bool MatchesAttributes(HtmlAttributeCollection attributes, TextSearch search) { foreach (var attribute in attributes) { if (search.IsMatch(attribute.Name) || search.IsMatch(attribute.Value)) { return(true); } } return(false); }
public static bool AttributeExists(this HtmlAttributeCollection collection, string name, string value) { if (collection == null) { return(false); } var attr = collection.AttributesWithName(name)?.FirstOrDefault() ?? null; return(attr != null && attr.Value == value); }
public static void AppendOrCreate(this HtmlAttributeCollection helper, string name, string value) { if (!helper.Contains(name)) { helper.Append(name, value); } else { helper[name].Value += value; } }
public static T GetValue <T>(this HtmlAttributeCollection attributes, string key, IFormatProvider formatProvider) { var value = attributes[key]?.Value; if (string.IsNullOrEmpty(value)) { return(default(T)); } T convertedValue = (T)Convert.ChangeType(value, typeof(T), formatProvider); return(convertedValue); }
public static void RemoveAttribute(this HtmlNode node, string attrName) { HtmlAttributeCollection attrs = node.Attributes; for (var i = 0; i < attrs.Count; i++) { var attr = attrs[i]; if (string.Equals(attr.Name, attrName, StringComparison.OrdinalIgnoreCase)) { node.Attributes.Remove(attr); break; } } }
//根据文本框中信息抽取指定节点 private void extract_info_Click(object sender, EventArgs e) { Template tm = new Template(); //获取模板 tm.createTem(this.Domtext.Text); //将模板放在Domtext中; attrs = tm.getattr(); //设置抽取属性; tag = tm.gettag(); //设置抽取标签; // tm.Extract("http://www.walmart.com/ip/VTech-CS6919-15-DECT-6.0-Expandable-Cordless-Phone-with-Caller-ID-and-Handset-Speakerphone-Red/45074431"); // this.webBrowser1.Navigate("http://www.walmart.com/ip/VTech-CS6919-15-DECT-6.0-Expandable-Cordless-Phone-with-Caller-ID-and-Handset-Speakerphone-Red/45074431"); nextextraturl(extractid); // partition_timer.Start(); }
public static Hashtable HtmlTable(string s) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(s); Hashtable htc = new Hashtable(); int index = 1; foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table")) { // table.Attributes // Console.WriteLine("Found: " + table.Id); HtmlAttributeCollection attrs = table.Attributes; // Console.Write(attrs.Count.ToString()); if (attrs.Count != 6) { continue; } foreach (HtmlNode row in table.SelectNodes("tr")) { // Console.WriteLine("row"); // Console.WriteLine(row.HasAttributes); int i = 0; Hashtable ht = new Hashtable(); foreach (HtmlNode cell in row.SelectNodes("th|td")) { string val = null; //Console.WriteLine(i); val = cell.InnerText; // Console.WriteLine("cell: " + cell.InnerText); //string sp = SelectSP(cell.InnerText.ToString()); if (i == 9) { string ss = Selectvalue(cell.InnerHtml, "a"); string u = "http://vip.win007.com/changeDetail/overunder.aspx?id=" + ss + "&companyid=3"; val = u; } ht.Add(i, val); i++; } htc.Add(index, ht); index++; } } return(htc); }
private static void addProps(StringBuilder dynamicObject, HtmlAttributeCollection attributes) { foreach (var attribute in attributes) { if (attribute.Value.StartsWith("@")) { dynamicObject.Append($".Add(\"{attribute.Name}\", {attribute.Value.Substring(1)})"); } else { dynamicObject.Append($".Add(\"{attribute.Name}\", \"{attribute.Value}\")"); } } }
private static List <string> GetCourses() { HtmlDocument boardHtml = new HtmlDocument(); boardHtml.LoadHtml(Driver.GetInstance.WebDrive.PageSource); List <string> Courses = new List <string>(); foreach (var Nodo in boardHtml.DocumentNode.CssSelect(".ic-DashboardCard__link")) { HtmlAttributeCollection atts = Nodo.Attributes; Courses.Add(atts.Where(a => a.Name.ToLower() == "href").FirstOrDefault().Value); } return(Courses); }
protected IEnumerable <ViewLayerControlAttribute> ConvertAttributes(HtmlAttributeCollection attributeCollection) { var convertedAttributes = attributeCollection .Where(attr => AttributeMap.ContainsKey(attr.Name)) .Select(attr => { if (attr.QuoteType == AttributeValueQuote.DoubleQuote) { return(new ViewLayerControlAttribute($"{AttributeMap[attr.Name]}", $"\"{attr.Value}\"")); } return(new ViewLayerControlAttribute($"{AttributeMap[attr.Name]}", $"'{attr.Value}'")); }); return(convertedAttributes); }
protected void InitXmlNode(XmlNode xmlNode, HtmlDocument htmlDoc) { Debug.Assert(xmlNode != null); Debug.Assert( xmlNode.OwnerDocument == htmlDoc.m_XmlNode.OwnerDocument || xmlNode.OwnerDocument == htmlDoc.m_XmlNode ); m_XmlNode = xmlNode; m_UpperName = null; m_Doc = htmlDoc; m_Attributes = new HtmlAttributeCollection(this); m_ChildNodeList = new HtmlNodeList(m_XmlNode.ChildNodes); }
public void createTem(String s) //根据纯文本得到节点属性 { HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(s); HtmlNode node = doc.DocumentNode.FirstChild; tag = node.Name; attrs = node.Attributes; foreach (var item in attrs) { attrString = " and " + "@" + item.Name + "=" + "'" + item.Value + "'"; //提取节点的属性集合 } attrString = attrString.Substring(5); attrString = "//" + tag + "[" + attrString + "]"; }
protected bool isAttributeValueEquals(HtmlAttributeCollection attributes, string attr, string str) { try { if (attributes.Contains(attr)) { if (attributes[attr].Value == str) { return(true); } } } catch (Exception) { } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Text.HtmlTagToken"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="HtmlTagToken"/>. /// </remarks> /// <param name="name">The name of the tag.</param> /// <param name="attributes">The attributes.</param> /// <param name="isEmptyElement"><c>true</c> if the tag is an empty element; otherwise, <c>false</c>.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="name"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="attributes"/> is <c>null</c>.</para> /// </exception> public HtmlTagToken (string name, IEnumerable<HtmlAttribute> attributes, bool isEmptyElement) : base (HtmlTokenKind.Tag) { if (name == null) throw new ArgumentNullException (nameof (name)); if (attributes == null) throw new ArgumentNullException (nameof (attributes)); Attributes = new HtmlAttributeCollection (attributes); IsEmptyElement = isEmptyElement; Id = name.ToHtmlTagId (); Name = name; }
internal HtmlAttributeCollection CreateTestCollection() { HtmlElement root = new HtmlElement("root"); HtmlAttributeCollection target = new HtmlAttributeCollection(root); HtmlAttribute attribute = new HtmlAttribute("first"); target.Add(attribute); attribute = new HtmlAttribute("second", "value"); target.Add(attribute); attribute = new HtmlAttribute("third", "\"another value\""); target.Add(attribute); return target; }
private static void Entitize(HtmlAttributeCollection collection) { foreach (HtmlAttribute at in collection) { at.Value = Entitize(at.Value); } }
public FlowedToHtmlTagContext (HtmlTagId tag) : base (tag) { attrs = HtmlAttributeCollection.Empty; }
public FlowedToHtmlTagContext (HtmlTagId tag, HtmlAttribute attr) : base (tag) { attrs = new HtmlAttributeCollection (new [] { attr }); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Text.HtmlTagToken"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="HtmlTagToken"/>. /// </remarks> /// <param name="name">The name of the tag.</param> /// <param name="isEndTag"><c>true</c> if the tag is an end tag; otherwise, <c>false</c>.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="name"/> is <c>null</c>. /// </exception> public HtmlTagToken (string name, bool isEndTag) : base (HtmlTokenKind.Tag) { if (name == null) throw new ArgumentNullException (nameof (name)); Attributes = new HtmlAttributeCollection (); Id = name.ToHtmlTagId (); IsEndTag = isEndTag; Name = name; }
/// <summary> /// This constructs a new Html element with the specified tag attributeName. /// </summary> public HtmlElement(string name) { this.nodes = new HtmlNodeCollection(this); this.attributes = new HtmlAttributeCollection(this); this.name = name; }