日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

vc获取网页内链接

發布時間:2025/4/16 c/c++ 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vc获取网页内链接 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.獨立代碼:

//-----------開始---------------------//
#include <atlbase.h>
#include <mshtml.h>
#include <winuser.h>
#include <comdef.h>
#include <string.h>
void EnumIE(void);//處理網頁
CComModule _Module;??//使用CComDispatchDriver ATL的智能指針,此處必須聲明
#include <atlcom.h>
void EnumAnchorElement(IHTMLDocument2 * pIHTMLDocument2);//獲取內嵌網頁

?

void EnumIE(void)??
{??
? CComPtr<IShellWindows> spShellWin;??
? HRESULT hr=spShellWin.CoCreateInstance(CLSID_ShellWindows);??
? if (FAILED(hr))??
? {??
? return;??
? }??????

? long nCount=0;??? //取得瀏覽器實例個數(Explorer和IExplorer)??
? spShellWin->get_Count(&nCount);??
? if (0==nCount)??
? {??
??? return;??
? }

? for(int i=0; i<nCount; i++)??
? {??
??? CComPtr<IDispatch> spDispIE;??
??? hr=spShellWin->Item(CComVariant((long)i), &spDispIE);??
??? if (FAILED(hr)) continue;
?
??? CComQIPtr<IWebBrowser2>spBrowser=spDispIE;??
??? if (!spBrowser) continue;
?
??? CComPtr<IDispatch> spDispDoc;??
??? hr=spBrowser->get_Document(&spDispDoc);??
??? if (FAILED(hr)) continue;
?
??? CComQIPtr<IHTMLDocument2>spDocument2 =spDispDoc;??
??? if (!spDocument2) continue;??????

?//Modify by jncao 2007-09-17
?//*******************************************************************************
?CString cIEUrl_Filter;? //設置的URL(必須是此URL的網站才有效);
??? cIEUrl_Filter="http://127.0.0.1/iAgent"; //設置過濾的網址
??? //*******************************************************************************

??? CComBSTR IEUrl;
?spBrowser->get_LocationURL(&IEUrl);
?CString cIEUrl_Get;???? //從機器上取得的HTTP的完整的URL;
?cIEUrl_Get=IEUrl;
?cIEUrl_Get=cIEUrl_Get.Left(cIEUrl_Filter.GetLength()); //截取前面N位

?if (strcmp(cIEUrl_Get,cIEUrl_Filter)==0)
?{
??? ?// 程序運行到此,已經找到了IHTMLDocument2的接口指針??????
??????? //EnumForm(spDocument2); //枚舉所有的表單??
??//EnumAllElement(spDocument2);//枚舉所有字段
??EnumAnchorElement(spDocument2);//獲取內嵌網頁
?}???
? }??
}


void EnumAnchorElement(IHTMLDocument2 * pIHTMLDocument2) //獲取內嵌網頁
{
?if (!pIHTMLDocument2) return;??????
?HRESULT?? hr;??

?CComQIPtr<IHTMLElementCollection> spAllElement;
?hr=pIHTMLDocument2->get_links(&spAllElement);//獲取所有網頁內所有內嵌網頁鏈接
?if (FAILED(hr))??return;?

?long nLength = 0;
?spAllElement->get_length (&nLength);
?for (int i = 0; i < nLength; i++)
?{
??????? CComPtr<IDispatch> pDisp;
??hr = spAllElement->item(COleVariant((long)i),COleVariant((long)0),&pDisp); //獲取單個鏈接

??if(SUCCEEDED(hr))
??{
???CComQIPtr <IHTMLAnchorElement, &IID_IHTMLAnchorElement> pElement(pDisp);
???BSTR bHref;
???pElement->get_href(&bHref);
???CString strHref=bHref;
???AfxMessageBox(strHref);
??}
?}

}

?

//-----------結束--------------------//

?

2.執行代碼:

void CDemoDlg::OnOK()
{
?// TODO: Add extra validation here
?::CoInitialize(NULL); //初始化COM
???? EnumIE();???????????? //枚舉瀏覽器??????
???? ::CoUninitialize();?? //釋放COM
?//CDialog::OnOK();
}

總結

以上是生活随笔為你收集整理的vc获取网页内链接的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。