首页 新闻 会员 周边 捐助

c#获取指定网页上的input标签,然后给了我一段代码,没看懂报错,求帮我看看很急

0
悬赏园豆:10 [已解决问题] 解决于 2019-01-02 10:12

监控网页
主要用
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;
TS朝暮的主页 TS朝暮 | 初学一级 | 园豆:10
提问于:2018-12-29 09:20
< >
分享
最佳答案
0

应该是获取html源文件,然后获取指定元素的值.

收获园豆:10
坐拥百态 | 初学一级 |园豆:184 | 2018-12-29 10:58

是的,正在解决,快好了,解决了两天了哈哈哈谢谢你帮我看问题

TS朝暮 | 园豆:10 (初学一级) | 2018-12-29 15:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册