本文整理汇总了C#中System.Windows.Forms.HtmlElement.GetElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlElement.GetElementsByTagName方法的具体用法?C# HtmlElement.GetElementsByTagName怎么用?C# HtmlElement.GetElementsByTagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.HtmlElement
的用法示例。
在下文中一共展示了HtmlElement.GetElementsByTagName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHistoryFromTable
public IList<HistoryInfo> GetHistoryFromTable(HtmlElement table)
{
IList<HistoryInfo> result = new List<HistoryInfo>();
if (table == null)
{
throw new ArgumentException();
}
HtmlElementCollection rows = table.GetElementsByTagName("tr");
if (rows == null || rows.Count == 0)
{
return result;
}
///The 1st row are columns' name
for (int i = 1; i < rows.Count; i++)
{
HtmlElement currentRow = rows[i];
HistoryInfo item = GetItemFromRow(currentRow);
if (item != null)
result.Add(item);
}
return result;
}
示例2: GetHtmlEntriesFromMobileHandelsbanken
private static void GetHtmlEntriesFromMobileHandelsbanken(
HtmlElement kontoEntriesElement, SortedList kontoEntries, SortedList newKontoEntries)
{
var newBatchOfKontoEntriesAlreadyRed = EntryAdder.GetNewBatchOfKontoEntriesAlreadyRed(kontoEntries, newKontoEntries);
foreach (HtmlElement htmlElement in kontoEntriesElement.GetElementsByTagName("LI"))
{
EntryAdder.AddNewEntryFromStringArray(
GetMobileHandelsbankenTableRow(htmlElement),
kontoEntries,
newKontoEntries,
newBatchOfKontoEntriesAlreadyRed);
}
}
示例3: GetHtmlElementsByAttr
public static IEnumerable<HtmlElement> GetHtmlElementsByAttr(HtmlElement parent_he, string attribute, string value = null, string tag = null)
{
HtmlElementCollection hec;
if (tag == null)
hec = parent_he.All;
else
hec = parent_he.GetElementsByTagName(tag);
foreach (HtmlElement he in hec)
{
//if (he.InnerText!= null && he.InnerText.Contains('$'))
//string className = ((mshtml.IHTMLElement)he.DomElement).className;
string a = he.GetAttribute(attribute);
if (a == null)
continue;
if (value == null || a == value)
yield return he;
}
}
示例4: SearchDiv
private HtmlElement SearchDiv(HtmlElement el)
{
if (el == null)
{
return null;
}
if (el.GetAttribute("className") == "WarningMessage PhaseOut")
{
return el;
}
HtmlElementCollection elc = el.GetElementsByTagName("div");
if (elc != null)
{
foreach (HtmlElement e in elc)
{
HtmlElement r = SearchDiv(e);
if (r != null)
{
return r;
}
}
}
return null;
}
示例5: UpdateUrlAbsolute
protected void UpdateUrlAbsolute(HtmlElement ele)
{
HtmlElementCollection eleColec = ele.GetElementsByTagName("IMG");
foreach (HtmlElement it in eleColec)
{
it.SetAttribute("src", it.GetAttribute("src"));
}
eleColec = ele.GetElementsByTagName("A");
foreach (HtmlElement it in eleColec)
{
it.SetAttribute("href", it.GetAttribute("href"));
}
if (ele.TagName == "A")
{
ele.SetAttribute("href", ele.GetAttribute("href"));
}
else if (ele.TagName == "IMG")
{
ele.SetAttribute("src", ele.GetAttribute("src"));
}
}
示例6: GetIViewObjectElement
private static IViewObject GetIViewObjectElement(HtmlElement htmlElement)
{
HtmlElementCollection collection = htmlElement.GetElementsByTagName("embed");
Trace.Assert(collection.Count == 0 || collection.Count == 1, "More then one embed or object found: " + htmlElement.InnerHtml);
if (collection.Count > 0)
{
IViewObject element = collection[0].DomElement as IViewObject;
if (element != null)
return element;
}
collection = htmlElement.GetElementsByTagName("object");
Trace.Assert(collection.Count == 0 || collection.Count == 1, "More then one embed or object found: " + htmlElement.InnerHtml);
if (collection.Count > 0)
{
return collection[0].DomElement as IViewObject;
}
return null;
}
示例7: ParseFinancialDetails
private static void ParseFinancialDetails(StockSerie stockSerie, StockFinancial financial, HtmlElement table)
{
HtmlElementCollection tables = table.GetElementsByTagName(("table"));
foreach (HtmlElement tbl in tables)
{
}
}
示例8: GetElements
private static List<HtmlElement> GetElements(HtmlElement hRoot,
string strTagName, string strAttribName, string strAttribValue)
{
List<HtmlElement> l = new List<HtmlElement>();
if(hRoot == null) { Debug.Assert(false); return l; }
if(string.IsNullOrEmpty(strTagName)) { Debug.Assert(false); return l; }
foreach(HtmlElement hEl in hRoot.GetElementsByTagName(strTagName))
{
if(!string.IsNullOrEmpty(strAttribName) && (strAttribValue != null))
{
string strValue = XmlUtil.SafeAttribute(hEl, strAttribName);
if(!strValue.Equals(strAttribValue, StrUtil.CaseIgnoreCmp))
continue;
}
l.Add(hEl);
}
return l;
}
示例9: DragCorner
private void DragCorner(HtmlElement container)
{
HtmlElement handle = container.GetElementsByTagName("div")[0];
HtmlElement txtarea = container.GetElementsByTagName("textarea")[0];
HtmlElementEventHandler handler = (sender, args) => MoveListener(sender, (HtmlElementEventArgs)args, container, txtarea);
/* Listen for 'mouse down' on handle to start the move listener */
handle.MouseDown += (mdSender, mdArgs) =>
{
locationX = mdArgs.ClientMousePosition.X;
locationY = mdArgs.ClientMousePosition.Y;
/* Start listening for mouse move on body */
webBrowser1.Document.MouseMove += handler;
};
/* Listen for 'mouse up' to cancel 'move' listener */
webBrowser1.Document.MouseUp +=
(sender, e) =>
{
webBrowser1.Document.MouseMove -= handler;
};
}
示例10: GetHtmlElementByFragment
public static HtmlElement GetHtmlElementByFragment(HtmlElement parent, string tag, string fragment)
{
HtmlElementCollection hec;
if (tag == null)
hec = parent.All;
else
hec = parent.GetElementsByTagName(tag);
foreach (HtmlElement he in hec)
if (he.OuterHtml.Contains(fragment))
return he;
return null;
}
示例11: GetHtmlElementByAttr
public static HtmlElement GetHtmlElementByAttr(HtmlElement parent, string tag, string attribute, string value)
{
HtmlElementCollection hec;
if (tag == null)
hec = parent.All;
else
hec = parent.GetElementsByTagName(tag);
foreach (HtmlElement he in hec)
//if (he.InnerText!= null && he.InnerText.Contains('$'))
//string className = ((mshtml.IHTMLElement)he.DomElement).className;
if (he.GetAttribute(attribute) == value)
return he;
return null;
}
示例12: getTableData
private static List<List<string>> getTableData(HtmlElement tbl)
{
List<List<string>> data = new List<List<string>>();
HtmlElementCollection rows = tbl.GetElementsByTagName("tr");
HtmlElementCollection cols; // = rows.GetElementsByTagName("th");
foreach (HtmlElement tr in rows)
{
List<string> row = new List<string>();
cols = tr.GetElementsByTagName("th");
foreach (HtmlElement td in cols)
{
row.Add(WebUtility.HtmlDecode(td.InnerText));
}
cols = tr.GetElementsByTagName("td");
foreach (HtmlElement td in cols)
{
row.Add(WebUtility.HtmlDecode(td.InnerText));
}
if (row.Count > 0) data.Add(row);
}
return data;
}
示例13: GetItemFromRow
public HistoryInfo GetItemFromRow(HtmlElement row)
{
HistoryInfo result = null;
HtmlElementCollection cols = row.GetElementsByTagName("td");
if (cols == null || cols.Count != 7 || cols[6].InnerText != "已开奖")
{
return result;
}
string roundId = cols[0].InnerText;
string time = cols[1].InnerText.Replace("\r\n", " ");
HtmlElementCollection imgs = cols[2].GetElementsByTagName("img");
if (imgs == null || imgs.Count != 7)
{
return result;
}
//<img src="http://image.juxiangyou.com/speed28/num14o.gif">
string src = imgs[6].GetAttribute("src");
int num = -1;
if (!string.IsNullOrEmpty(src))
{
string numStr = src.Replace("http://image.juxiangyou.com/speed28/num", "").Replace("o.gif", "");
if (!string.IsNullOrEmpty(numStr))
{
if (!int.TryParse(numStr, out num))
{
throw new ArgumentException();
}
}
}
HtmlElementCollection totalBeans = cols[3].GetElementsByTagName("span");
long totalAmount = 0;
if (totalBeans != null && totalBeans.Count == 1)
{
string totalAmountStr = totalBeans[0].InnerText.Replace(",", "");
if (!string.IsNullOrEmpty(totalAmountStr))
{
if (!long.TryParse(totalAmountStr, out totalAmount))
{
throw new ArgumentException();
}
}
}
int winner = 0;
string winnerStr = cols[4].InnerText.Replace(",", "");
if (!string.IsNullOrEmpty(winnerStr))
{
if (!int.TryParse(winnerStr, out winner))
{
throw new ArgumentException();
}
}
long amount = 0, stake = 0;
//<td bgcolor="#FFFFFF" class="a6"><span class="udcl">收:0</span><br><span class="da3">竞:0</span></td>
HtmlElementCollection beans = cols[5].GetElementsByTagName("span");
if (beans != null && beans.Count == 2)
{
string winStr = beans[0].InnerText.Replace("收:", "").Replace(",", "");
if (!string.IsNullOrEmpty(winStr))
{
if (!long.TryParse(winStr, out amount))
{
throw new ArgumentException();
}
}
string staketr = beans[1].InnerText.Replace("竞:", "").Replace(",", "");
if (!string.IsNullOrEmpty(staketr))
{
if (!long.TryParse(staketr, out stake))
{
throw new ArgumentException();
}
}
}
result = new HistoryInfo();
result.RoundId = roundId;
result.Result = num;
result.Stake = stake;
result.TotalAmount = totalAmount;
result.WinnerNum = winner;
result.Amount = amount;
result.Date = string.Format("{0}-{1}", DateTime.Now.Date.Year, time);
return result;
}
示例14: FindControlsByClass
/// <summary>
/// Finds the controls by class.
/// </summary>
/// <param name="parent">The parent control.</param>
/// <param name="tagName">Name of the HTML tag.</param>
/// <param name="className">Name of the class to find.</param>
/// <returns>A List of HtmlElements containing controls with the specified class name.</returns>
private List<HtmlElement> FindControlsByClass(HtmlElement parent, string tagName, string className)
{
List<HtmlElement> controlsWithMatchingClass = new List<HtmlElement>();
if (this.WebBrowser.Document != null)
{
HtmlElementCollection controlCollection = parent.GetElementsByTagName(tagName);
foreach (HtmlElement element in controlCollection)
{
if (element.OuterHtml.ToUpper().Contains(className.ToUpper()))
{
controlsWithMatchingClass.Add(element);
}
}
}
return controlsWithMatchingClass;
}
示例15: ImportPriv
private static void ImportPriv(PwDatabase pd, HtmlElement hBody)
{
#if DEBUG
bool bHasSpanCaptions = (GetElements(hBody, "SPAN", "class",
"caption").Count > 0);
#endif
foreach(HtmlElement hTable in hBody.GetElementsByTagName("TABLE"))
{
Debug.Assert(XmlUtil.SafeAttribute(hTable, "width") == "100%");
string strRules = XmlUtil.SafeAttribute(hTable, "rules");
string strFrame = XmlUtil.SafeAttribute(hTable, "frame");
if(strRules.Equals("cols", StrUtil.CaseIgnoreCmp) &&
strFrame.Equals("void", StrUtil.CaseIgnoreCmp))
continue;
PwEntry pe = new PwEntry(true, true);
PwGroup pg = null;
bool bNotesHeaderFound = false;
foreach(HtmlElement hTr in hTable.GetElementsByTagName("TR"))
{
// 7.9.1.1+
List<HtmlElement> lCaption = GetElements(hTr, "SPAN",
"class", "caption");
if(lCaption.Count == 0)
lCaption = GetElements(hTr, "DIV", "class", "caption");
if(lCaption.Count > 0)
{
string strTitle = ParseTitle(XmlUtil.SafeInnerText(
lCaption[0]), pd, out pg);
ImportUtil.AppendToField(pe, PwDefs.TitleField, strTitle, pd);
continue; // Data is in next TR
}
// 7.9.1.1+
if(hTr.GetElementsByTagName("TABLE").Count > 0) continue;
HtmlElementCollection lTd = hTr.GetElementsByTagName("TD");
if(lTd.Count == 1)
{
HtmlElement e = lTd[0];
string strText = XmlUtil.SafeInnerText(e);
string strClass = XmlUtil.SafeAttribute(e, "class");
if(strClass.Equals("caption", StrUtil.CaseIgnoreCmp))
{
Debug.Assert(pg == null);
strText = ParseTitle(strText, pd, out pg);
ImportUtil.AppendToField(pe, PwDefs.TitleField, strText, pd);
}
else if(strClass.Equals("subcaption", StrUtil.CaseIgnoreCmp))
ImportUtil.AppendToField(pe, PwDefs.UrlField,
ImportUtil.FixUrl(strText), pd);
else if(strClass.Equals("field", StrUtil.CaseIgnoreCmp))
{
// 7.9.2.5+
if(strText.EndsWith(":") && !bNotesHeaderFound)
bNotesHeaderFound = true;
else
ImportUtil.AppendToField(pe, PwDefs.NotesField,
strText.Trim(), pd, MessageService.NewLine, false);
}
else { Debug.Assert(false); }
}
else if((lTd.Count == 2) || (lTd.Count == 3))
{
string strKey = XmlUtil.SafeInnerText(lTd[0]);
string strValue = XmlUtil.SafeInnerText(lTd[lTd.Count - 1]);
if(lTd.Count == 3) { Debug.Assert(string.IsNullOrEmpty(lTd[1].InnerText)); }
if(strKey.EndsWith(":")) // 7.9.1.1+
strKey = strKey.Substring(0, strKey.Length - 1);
if(strKey.Length > 0)
ImportUtil.AppendToField(pe, MapKey(strKey), strValue, pd);
else { Debug.Assert(false); }
}
else { Debug.Assert(false); }
}
if(pg != null) pg.AddEntry(pe, true);
#if DEBUG
else { Debug.Assert(bHasSpanCaptions); }
#endif
}
}