监控网页
主要用
using mshtml;
using SHDocVw;
//获取页面和框架中对应元素
private IHTMLInputTextElement getInputTextElement(IHTMLDocument2 document, string id)
{
var obj = (document as IHTMLDocument3).getElementById(id) as IHTMLInputTextElement;
if (obj == null)
{
IHTMLFramesCollection2 frames = (IHTMLFramesCollection2)document.frames;
for (int i = 0; i < frames.length; i++)
{
try
{
IHTMLWindow2 frame = frames.item(i) as IHTMLWindow2;
IHTMLDocument2 frameDoc = frame.document;
obj = (frameDoc as IHTMLDocument3).getElementById(id) as IHTMLInputTextElement;
if (obj != null)
{
break;
}
}
catch
{
}
}
}
return obj;
}
private IHTMLSelectElement getSelectElement(IHTMLDocument2 document, string id)
{
var obj = (document as IHTMLDocument3).getElementById(id) as IHTMLSelectElement;
if (obj == null)
{
IHTMLFramesCollection2 frames = (IHTMLFramesCollection2)document.frames;
for (int i = 0; i < frames.length; i++)
{
try
{
IHTMLWindow2 frame = frames.item(i) as IHTMLWindow2;
IHTMLDocument2 frameDoc = frame.document;
obj = (frameDoc as IHTMLDocument3).getElementById(id) as IHTMLSelectElement;
if (obj != null)
{
break;
}
}
catch
{
}
}
}
return obj;
}
private IHTMLInputButtonElSHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
{
string url = ie.LocationURL.ToUpper();
//地址匹配 getRegQuery
//if (url.IndexOf("GETREGQUERY") >= 0)
if (isLockUrl(url))
{
IHTMLDocument2 document = ie.Document as IHTMLDocument2;
while (document.readyState != "complete")
{
Thread.Sleep(500);
}
//业务类型
string gnid = "";
var gnidObj = getSelectElement(document, "gnid");
if (gnidObj != null)
{
gnid = gnidObj.value;
//默认设置
//身份证明号码
var sfzmhmObj = getInputTextElement(document, "sfzmhm");
if (sfzmhmObj != null)
{
sfzmhmObj.readOnly = false;
}
//号牌种类
var hpzlObj = getSelectElement(document, "hpzl");
if (hpzlObj != null)
{
}
var hpzl1Obj = getSelectElement(document, "hpzl1");
if (hpzl1Obj != null)
{
}
//号牌号码
var hphmObj = getInputTextElement(document, "hphm");
if (hphmObj != null)
{
hphmObj.readOnly = false;
应该是获取html源文件,然后获取指定元素的值.
是的,正在解决,快好了,解决了两天了哈哈哈谢谢你帮我看问题