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();
        }
    }

  • 相关阅读:
    开源Jabber(XMPP) IM服务器介绍
    ejabberd、jabber、jabberd、xmpp辨析
    分布式与集群的区别
    浅谈Javascript事件模拟
    理清javascript的相关概念 DOM和BOM
    js基础学习第一天(关于DOM和BOM)一
    处理机调度和死锁
    C++11 之 " = delete "
    小数的二进制表示
    二进制数的插入
  • 原文地址:https://www.cnblogs.com/kernel0815/p/4755722.html
Copyright © 2011-2022 走看看