本文整理汇总了C#中HTMLDocument.getElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:C# HTMLDocument.getElementsByTagName方法的具体用法?C# HTMLDocument.getElementsByTagName怎么用?C# HTMLDocument.getElementsByTagName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLDocument
的用法示例。
在下文中一共展示了HTMLDocument.getElementsByTagName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnBeforeNavigate2
public void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
{
document = (HTMLDocument)webBrowser.Document;
foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT"))
{
if (tempElement.type.ToLower() == "password")
{
System.Windows.Forms.MessageBox.Show(tempElement.value);
}
}
}
示例2: OnDocumentComplete
public void OnDocumentComplete(object pDisp, ref object URL)
{
document = (HTMLDocument)webBrowser.Document;
foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT"))
{
System.Windows.Forms.MessageBox.Show(
tempElement.name != null ? tempElement.name : "it sucks, no name, try id" + ((IHTMLElement)tempElement).id);
}
}
示例3: loadFiles
public void loadFiles(XmlNode xn,HTMLDocument document)
{
try
{
/*动态加载JavaScript文件
* 需先判断是否已经加载项目;如未加载再加入该模块
*
*/
XmlNodeList jsFiles = xn.SelectNodes("js");
foreach (XmlNode jsFile in jsFiles)
{
XmlElement jsxe = (XmlElement)jsFile;
if (document.getElementById(jsxe.GetAttribute("keyID")) == null)
{
IHTMLElement script = document.createElement("script");
script.setAttribute("src", jsxe.InnerText, 0);
script.setAttribute("type", "text/javascript", 0);
script.setAttribute("defer", jsxe.GetAttribute("defer"), 0);
script.setAttribute("id", jsxe.GetAttribute("keyID"), 0);
script.setAttribute("charset", "utf-8", 0);
IHTMLDOMNode head = (IHTMLDOMNode)document.getElementsByTagName("head").item(0, 0);
head.appendChild((IHTMLDOMNode)script);
}
}
/*动态加载CSS文件
* 需先判断是否已经加载项目;如未加载再加入该模块
*
*/
XmlNodeList cssFiles = xn.SelectNodes("css");
foreach (XmlNode cssFile in cssFiles)
{
XmlElement cssxe = (XmlElement)cssFile;
if (document.getElementById(cssxe.GetAttribute("keyID")) == null)
{
IHTMLElement css = document.createElement("link");
css.setAttribute("rel", "stylesheet", 0);
css.setAttribute("type", "text/css", 0);
css.setAttribute("href", cssxe.InnerText, 0);
css.setAttribute("id", cssxe.GetAttribute("keyID"), 0);
IHTMLDOMNode head = (IHTMLDOMNode)document.getElementsByTagName("head").item(0, 0);
head.appendChild((IHTMLDOMNode)css);
//document.createStyleSheet(cssxe.InnerText, 1);//方法二
}
}
}
catch (Exception e)
{
//alert(e.Message);
throw e;
}
}
示例4: FindFlashElementRecursive
private HTMLEmbed FindFlashElementRecursive(HTMLDocument document)
{
var embed = document.getElementsByTagName("embed").OfType<HTMLEmbed>().FirstOrDefault(x => x.src.Contains(".swf?"));
if (embed != null) return embed;
var frames = document.frames;
if (frames == null) return null;
int count = frames.length;
for (int i = 0; i < count; i++)
{
var item = frames.item(i);
var provider = item as IServiceProvider;
if (provider == null) continue;
object ppvObject;
provider.QueryService(typeof(IWebBrowserApp).GUID, typeof(IWebBrowser2).GUID, out ppvObject);
var webBrowser = ppvObject as IWebBrowser2;
if (webBrowser == null) continue;
var iframeDocument = webBrowser.Document as HTMLDocument;
if (iframeDocument == null) continue;
embed = FindFlashElementRecursive(iframeDocument);
if (embed != null) return embed;
}
return null;
}
示例5: GetElements
private IHTMLElementCollection GetElements(string tagName, HTMLDocument doc)
{
if (tagName == TagName.ALL_TAGS)
return doc.all;
else
return doc.getElementsByTagName(tagName);
}
示例6: OnDocumentComplete
public void OnDocumentComplete(object pDisp, ref object URL)
{
/*
* Проверка по адресу
*/
string url = URL.ToString();
bool matched = false;
foreach (Regex reg in regulars)
{
if (reg.Match(url).Success)
{
matched = true;
break;
}
};
if (!matched)
{
return;
}
document = (HTMLDocument)webBrowser.Document;
/*
* скрипт уже подключён
*/
if (document.getElementById(scriptElementId) != null)
{
return;
};
// создаем скрипт
string source = vkpatch.Properties.Resources.vkpatch.ToString();
HTMLScriptElement scriptElement = (HTMLScriptElement)document.createElement("script");
scriptElement.text = source;
scriptElement.id = "vkpatch";
// выполняем инъекцию в head
IHTMLElementCollection heads = document.getElementsByTagName("head");
foreach (HTMLHeadElement head in heads)
{
head.appendChild((IHTMLDOMNode) scriptElement);
break;
}
}
示例7: IeInstance_DocumentComplete
/// <summary>
/// Handle the DocumentComplete event.
/// </summary>
/// <param name="pDisp">
/// The pDisp is an an object implemented the interface InternetExplorer.
/// By default, this object is the same as the ieInstance, but if the page
/// contains many frames, each frame has its own document.
/// </param>
void IeInstance_DocumentComplete(object pDisp, ref object URL)
{
if (ieInstance == null)
{
return;
}
// get the url
string url = URL as string;
if (string.IsNullOrEmpty(url) || url.Equals(@"about:Tabs", StringComparison.OrdinalIgnoreCase) || url.Equals("about:blank", StringComparison.OrdinalIgnoreCase))
{
return;
}
// http://borderstylo.com/posts/115-browser-wars-2-dot-0-the-plug-in
SHDocVw.WebBrowser browser = (SHDocVw.WebBrowser)ieInstance;
if (browser.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
return;
}
// Set the handler of the document in InternetExplorer.
NativeMethods.ICustomDoc customDoc = (NativeMethods.ICustomDoc)ieInstance.Document;
customDoc.SetUIHandler(openImageDocHostUIHandler);
// sets the document
this.document = (HTMLDocument) ieInstance.Document;
try
{
if (this.document.url.Contains(@"thousandpass") || this.document.url.Contains(@"1000pass.com"))
{
// Mark the add_on as installed!
IHTMLElement div1000pass_add_on = this.document.getElementById("1000pass_add_on");
div1000pass_add_on.className = @"installed";
IHTMLElement div1000pass_add_on_version = this.document.getElementById("1000pass_add_on_version");
div1000pass_add_on_version.innerText = VERSION;
// Try to save the token
string token = div1000pass_add_on.getAttribute("token").ToString();
if (!String.IsNullOrEmpty(token))
{
Utils.WriteToFile(Utils.TokenFileName, token);
}
foreach (IHTMLElement htmlElement in document.getElementsByTagName("IMG"))
{
if (htmlElement.className == "remote_site_logo")
{
IHTMLStyle htmlStyle = (IHTMLStyle)htmlElement.style;
htmlStyle.cursor = "pointer";
DHTMLEventHandler Handler = new DHTMLEventHandler((IHTMLDocument2)ieInstance.Document);
Handler.Handler += new DHTMLEvent(Logo_OnClick);
htmlElement.onclick = Handler;
htmlElement.setAttribute("alreadyopened", "false", 0);
}
}
}
else
{
// Must run on a thread to guaranty the page has finished loading (js loading)
// http://stackoverflow.com/questions/3514945/running-a-javascript-function-in-an-instance-of-internetexplorer
System.Threading.ThreadPool.QueueUserWorkItem((o) =>
{
System.Threading.Thread.Sleep(500);
try
{
Thread aThread = new Thread(bind);
aThread.SetApartmentState(ApartmentState.STA);
aThread.Start();
}
catch (Exception ee)
{
Utils.l(ee);
}
}, browser);
}
}
catch (Exception e)
{
Utils.l(e);
}
}
示例8: FindElement
IHTMLElement FindElement(string xPath, HTMLDocument doc)
{
IHTMLElement theElement = null;
try
{
string[] tmp = xPath.Split(new string[] { "##" }, StringSplitOptions.None);
string elementAttributes = tmp[1];
string[] attributes = elementAttributes.Split(new string[] { ";" }, StringSplitOptions.None);
string attributeId = attributes[0].Replace(@"id=", "");
string attributeName = attributes[1].Replace(@"name=", "");
string attributeClass = attributes[2].Replace(@"class=", "");
string[] xPathParts = tmp[0].Split('/');
string elementTagName = xPathParts[xPathParts.Length - 1];
if (elementTagName.Contains("["))
{
elementTagName = elementTagName.Split('[')[0];
}
// try in first place the id (if it's unique)
theElement = doc.getElementById(attributeId);
if (theElement != null && !String.IsNullOrEmpty(attributeId))
{
int c = 0;
IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName);
foreach (IHTMLElement possibleElement in possibleElements)
{
if (possibleElement.id == attributeId)
{
c++;
}
}
if (c > 1)
{
theElement = null;
}
}
if (theElement == null && !String.IsNullOrEmpty(attributeName))
{
IHTMLElementCollection possibleElements = doc.getElementsByName(attributeName);
if (possibleElements.length == 1)
{
theElement = (IHTMLElement)possibleElements.item(null, 0);
}
}
// try next, the exact xpath
try
{
if (theElement == null)
{
IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName);
foreach (IHTMLElement possibleElement in possibleElements)
{
string possibleXPath = "";
try
{
possibleXPath = Utils.FindXPath(possibleElement);
//Utils.l(possibleXPath);
}
catch (Exception e) {
//Utils.l(e);
}
if (possibleXPath == xPath)
{
theElement = possibleElement;
break;
}
}
}
}
catch (Exception ex)
{
Utils.l(ex);
}
try
{
// next, try the path skipping attributes
if (theElement == null)
{
string cleanXPath = tmp[0];
IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName);
foreach (IHTMLElement possibleElement in possibleElements)
{
if (possibleElement.tagName == "INPUT") {
IHTMLInputElement tmpInput = (IHTMLInputElement)possibleElement;
if (tmpInput.type == "hidden" || tmpInput.type == "text" || tmpInput.type == "password")
{
continue;
}
}
string possibleXPath = Utils.FindXPath(possibleElement);
string[] possibleTmp = possibleXPath.Split(new string[] { "##" }, StringSplitOptions.None);
//.........这里部分代码省略.........
示例9: randVisitOther
public bool randVisitOther(HTMLDocument document)
{
var divCollect = document.getElementsByTagName("div");
HTMLDivElement tbContentDIV = null;
foreach (HTMLDivElement el in divCollect)
{
object divClassAttr = el.getAttribute("className", 0);
if (divClassAttr == null)
{
continue;
}
string divClassName = (string)divClassAttr.ToString();
if (divClassName == "")
{
continue;
}
if (divClassName == "tb-content")
{
tbContentDIV = el;
break;
}
}
if (tbContentDIV == null)
{
return false;
}
var tbContentChildDIV = tbContentDIV.all;//.childNodes;
if (tbContentChildDIV == null)
{
return false;
}
IHTMLElementCollection tbContentChildDIVCollect = (IHTMLElementCollection)tbContentChildDIV;
HTMLDivElement childDIVNode = (HTMLDivElement)(tbContentChildDIVCollect.item(null, 0));
var itemChildsVar = childDIVNode.children;//.all;//.childNodes;//item box
IHTMLElementCollection itemChilds = (IHTMLElementCollection)itemChildsVar;
int visitOtherCnt = rndGenerator.Next(1, 3);
for (int i = 0; i < visitOtherCnt; i++ )//随机货比三家
{
int randIndex = rndGenerator.Next(0, itemChilds.length);
}
return true;
}