zoukankan      html  css  js  c++  java
  • c++ 实现百度自动搜索

    void CAttendanceRobotDlg::DocumentCompleteExplorer4(LPDISPATCH pDisp, VARIANT* URL)
    {
        // TODO: Add your message handler code here
        HRESULT   hr;
        LPUNKNOWN lpUnknown;
        LPUNKNOWN lpUnknownWB = NULL;
        LPUNKNOWN lpUnknownDC = NULL;
        IHTMLElementCollection *objAllElement = NULL;
        IHTMLDocument2 *objDocument = NULL;
        CString strUrl, strTemp;
    
        lpUnknown = m_pBrowser->GetControlUnknown();
        ASSERT(lpUnknown);
    
        if (lpUnknown)
        {
            hr = lpUnknown->QueryInterface(IID_IUnknown, (LPVOID*)&lpUnknownWB);
            ASSERT(SUCCEEDED(hr));
            if (FAILED(hr))
            {
                LOGD(L"QueryInterface IID_IUnknown failed.");
                return;
            }
    
            hr = pDisp->QueryInterface(IID_IUnknown, (LPVOID*)&lpUnknownDC);
            ASSERT(SUCCEEDED(hr));
            if (SUCCEEDED(hr) && lpUnknownWB == lpUnknownDC)
            {
                // The document has finished loading.
                strUrl = m_pBrowser->get_LocationURL();
                if (strUrl.IsEmpty())
                {
                    LOGD(L"get_LocationURL strUrl.IsEmpty().");
                    return;
                }
                objDocument = (IHTMLDocument2*)m_pBrowser->get_Document();
                objDocument->get_all(&objAllElement);
                if (strUrl == _T("http://www.baidu.com/"))
                {
                    CComPtr<IDispatch>pDisp;
                    objAllElement->item(COleVariant(_T("kw")), COleVariant((long)0), &pDisp);
                    CComQIPtr<IHTMLElement, &IID_IHTMLElement>pElement;
                    if (pDisp == NULL)
                    {
                        LOGD(L"pDisp == NULL.");
                        return;
                    }
                    else
                    {
                        pElement = pDisp;
                        pElement->put_innerText(_T("Hello")); //填充表单
                    }
    
                    VARIANT   name;
                    CComBSTR   tag;
                    long     index;
                    objAllElement->get_length(&index);
                    name.vt = VT_I4;
                    for (long i = 0; i < index; i++)//遍历所有元素,通过id属性获取值
                    {
                        name.lVal = i;
                        IDispatch   *   pDispatch = NULL;
                        objAllElement->item(name, name, &pDispatch);
                        IHTMLElement*   spElement;
                        pDispatch->QueryInterface(IID_IHTMLElement, (void**)&spElement);
                        BSTR   tag;
                        spElement->get_id(&tag);
                        CString   ss(tag);
                        if (ss == "su")
                        {
                            spElement->click();
                        }
    
                        spElement->Release();
                    }
                }
            }
        }
    
        if (lpUnknownWB)
        {
            lpUnknownWB->Release();
        }
    
        if (lpUnknownDC)
        {
            lpUnknownDC->Release();
        }
    }

  • 相关阅读:
    new Date()导致日期增加了一天
    我的Visual Studio 2013常用快捷键
    15款最好的 jQuery Modal(模态窗口)插件
    WebFormViewEngine及用户控件寻址bug
    车聘网框架及源码介绍
    HTTP超文本传输协议-HTTP/1.1中文版
    从客户端(SeekingJobs="<B>·</B> 物流规划,<B>·</...")中检测到有潜在危险的 Request.Form 值。
    UrlRewriter && IIS7
    C#如何通过反射调用带有ref或者out的参数的方法
    用Razor語法寫範本-RazorEngine組件介紹
  • 原文地址:https://www.cnblogs.com/kernel0815/p/4755722.html
Copyright © 2011-2022 走看看