比如说http://www.d7d8.cn/页面中的百度广告,点击其中的某个广告,会弹出一个页面,地址类似:http://sf.baidu.com/cpro.php?&e=dj0xJms9MzcyODE2NSZzPWh0dHAlM0ElMkYlMkZzaC50b3BzdHVkeS5jb20uY24lMkZsYW5ndWFnZSUyRmR1c2hpJTJG7bf3e4ae5e734f366ffa99fde1f5e52763129278&n=bdwxl_d7d8_cpr&im=2&referer=http%3A%2F%2Fwww.d7d8.cn%2F
请问怎么VC实现取得网页中广告的这个地址?

解决方案 »

  1.   

    下面的代码是修改某个链接的URL
    ///////////////////////////////////////////////////////////////////////////////////////
    //change_anchor_href
    //If   it   works,   it   is   written   by   masterz,otherwise   I   don't
    //know   who   writes   it^_^
    ///////////////////////////////////////////////////////////////////////////////////////
    void   change_anchor_href()
    {
    //CComQIPtr<IWebBrowser2>   m_spBrowser;
    HRESULT   hr;
    if   (m_spBrowser   !=   NULL)
    {
    IDispatchPtr   spDisp=NULL;
    hr=m_spBrowser->get_Document(&spDisp);
    if(SUCCEEDED(hr)&&   spDisp!=   NULL   )
    {
    IHTMLDocument2Ptr   spHtmlDocument(spDisp);
    IHTMLElementPtr   spHtmlElement;
    spHtmlDocument->get_body(&spHtmlElement);
    IHTMLElementCollection*   pColl=NULL;
    hr=spHtmlDocument->get_all(&pColl);
    if(pColl!=NULL&&SUCCEEDED(hr))
    {
    IHTMLElement*   pElem=NULL;
    _variant_t   index;
    index.vt=VT_I4;
    IDispatchPtr   disp;
    long   num;
    hr=pColl->get_length(&num);
    if(SUCCEEDED(hr))
    {
    for(long   i=0;i<num;i++)
    {
    index.intVal=i;
    hr=pColl->item(index,index,&disp);
    IHTMLAnchorElementPtr   pAnchorElement;
    if(SUCCEEDED(hr)&&disp!=NULL)
    {
    hr=disp->QueryInterface(&pAnchorElement);
    }
    if   (SUCCEEDED(hr)&&   pAnchorElement   !=   NULL)
    {
    pAnchorElement->put_href(_bstr_t("c:\\tmp\\link.htm"));
    }}
    }
    pColl->Release();
    }
    }
    }

      

  2.   

    先找到窗口,然后由窗口句柄得到IWebBrowser2指针,然后调用GetlocationUrl方法
      

  3.   

    俺比较菜,看不怎么明白。
    比如有这么个.htm文件
    <html>
    <body>
    <script type="text/javascript">
    var arrBaiduCproConfig=new Array();
    arrBaiduCproConfig['uid'] = 122571;
    arrBaiduCproConfig['n'] = 'bdwxl_d7d8_cpr';
    arrBaiduCproConfig['tm'] = 20;
    arrBaiduCproConfig['cm'] = 76;
    arrBaiduCproConfig['um'] = 26;
    arrBaiduCproConfig['w'] = 220;
    arrBaiduCproConfig['h'] = 250;
    arrBaiduCproConfig['wn'] = 1;
    arrBaiduCproConfig['hn'] = 4;
    arrBaiduCproConfig['ta'] = 'right';
    arrBaiduCproConfig['tl'] = 'bottom';
    arrBaiduCproConfig['bu'] = 0;
    arrBaiduCproConfig['bd'] = '#CC0000';
    arrBaiduCproConfig['bg'] = '#ffffff';
    arrBaiduCproConfig['tt'] = '#0000ff';
    arrBaiduCproConfig['ct'] = '#000000';
    arrBaiduCproConfig['url'] = '#666666';
    arrBaiduCproConfig['bdl'] = '#ffffff';
    arrBaiduCproConfig['rad'] = 1;
    </script>
    <script type="text/javascript"
     src="http://cpro.baidu.com/cpro/ui/ui.js">
    </script>
    <script type="text/javascript">
    <!--
    document.write(baiduCproIFrame());
    -->
    </script>
    </body>
    </html>
    如果不麻烦的话,楼上能否给个简单的程序,获取页面中广告的url.
    我的email:[email protected]
      

  4.   

    IHTMLDocument2Ptr htmlDoc2;
    htmlDoc2.Attach(GetHtmlDocument(strHTML));
    IHTMLElementCollectionPtr htmlImages;
    htmlDoc2->get_images(&htmlImages);
    long num;
    htmlImages->get_length(&num);
    for (long i = 0;i < num;++ i)
    {
    _variant_t index(i);
    IDispatchPtr itemDisp;
    HRESULT hr = htmlImages->item( index, index, &itemDisp);
    if FAILED(hr) return  "";
    IHTMLImgElementPtr imageItem;
    itemDisp->QueryInterface(__uuidof(IHTMLImgElement),(LPVOID*)&imageItem); BSTR bstrSrc;
    imageItem->get_href(&bstrSrc);
    UnEscapeInplace(bstrSrc); _bstr_t  bstrPath(bstrSrc,true);
    .......................
    参考.
      

  5.   

    mike 说说有这么个问题,
    来看看 .....2楼的程序倒是可以参考一下 ....