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

  • 相关阅读:
    内存溢出常见原因分析
    内存溢出,与内存泄露
    ping不通linux服务器排查
    内存,缓存,cpu,硬盘关系
    cpu 基础知识
    sql查询以及常见问题理解解析
    月入一万,活在北京 (zz)
    超越信息和通讯 迎接新一轮数字化变革 (转载)
    The specified DSN contains an architecture mismatch between the Driver and Application (zz.IS2120@B)
    Excel .xls文件导入、导出 的例子
  • 原文地址:https://www.cnblogs.com/kernel0815/p/4755722.html
Copyright © 2011-2022 走看看