如果没有, 我要如何获得当前页面的DOM , 并模拟鼠标的onclick();
注: 页面不是我编写的, 比如我获得了csdn的主页面, 我希望我的c#程序能自动填写登陆信息, 并且点击登陆按钮
用webbrowser可以加载页面并操作里面的内容
public mshtml.IHTMLDocument2 getIHTMLDocument2ByUrl(string url)
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore") && ie.LocationURL == url)
{
return ie.Document as mshtml.IHTMLDocument2;
}
}
return null;
}
public mshtml.IHTMLElement[] getCandidateTagList(mshtml.IHTMLDocument2 doc)
{
mshtml.IHTMLElementCollection elements = (mshtml.IHTMLElementCollection)doc.all.tags("a");
int countIt = 0;
foreach (mshtml.IHTMLElement item in elements)
{
if ( !Convert.IsDBNull ( item.getAttribute("usercard")) && !Convert.IsDBNull(item.getAttribute("node-type")) )
{
countIt = countIt + 1;
}
}
mshtml.IHTMLElement[] candidateTagList = new mshtml.IHTMLElement[countIt];
int candidateTagList_index = 0;
foreach (mshtml.IHTMLElement item in elements)
{
if (!Convert.IsDBNull(item.getAttribute("usercard")) && !Convert.IsDBNull(item.getAttribute("node-type")))
{
candidateTagList[candidateTagList_index] = item;
candidateTagList_index = candidateTagList_index + 1;
}
}
return candidateTagList;
}