Extract all links

zhaozj2021-02-16  59

Does the text have seen the "Internet Express" "Internet Express Download All Links"? Want to implement him, we can do this: IE has a few useful interfaces, we can use him to extract all links to get all the links with htmldocument2, get the IHTMLELEMENTCOLLECTION interface, then get the IHTMLANChorElement, and the get_href of the IHTMLANChorElement interface It is what we want, through the loop acquisition, we can get all the links to the web page! {TCHAR HostName [2 * MAX_PATH]; CComPtr spDispatch; CComQIPtr pDoc2; CComPtr pElementCol; CComPtr pLoct; // TODO: Add your control notification handler code here int n = m_LinksList .GetItemcount (); // getCount (); for (int i = 0; i Release ();}} m_linkslist.deleteallItems (); m_linksnum = 0; log ("**************************************** *********************** "); log (" / r / n "); if (m_spshwinds) {INT n = m_spshwinds-> getCount (); for (int i = 0; i item (v); shdocvw :: iWebBrowser2ptr spbrowser (SPDISP) ; / / Generate an IE window smart pointer if (spbrowser) {// Get the IHTMLDocument2 interface if (SUCCEEDED R-> Get_Document (& SPDISPATCH))))) PDOC2 = SPDISPATCH; if (PDOC2! = NULL) {

// Get IHTMLElementCollection interfaces if (SUCCEEDED (pDoc2-> get_links (& pElementCol))) {// AfxMessageBox ( "IHTMLElementCollection"); long p = 0; if (SUCCEEDED (pElementCol-> get_length (& p))) if (p! = 0) {m_LINKSNUM = M_LINKSNUM P; Updatedata (false); for (long i = 0; i <= (p-1); i ) {bstr string; _variant_t index = i; if (successmeded (startcol-> item (INDEX, INDEX, & SPDISPATCH))) / / Find the IHTMLANChorElement interface if (SUCCEEDED (Spdispatch-> Queryinterface (IID_IHTMLANCHORELEINTERFACE (IID_IHTMLANCHORELENTERFACE (IID_IHTMLANCHORELEMENT, (Void **))) // Get Link PLOCT-> Get_href (& string); ZeromeMory (Hostname, 2 * max_path); lstrcpy (hostname, _bstr_t (string));

// inserted into the link list in m_LinksList.InsertItem (i, HostName); m_LinksList.SetCheck (i, TRUE); pLoct-> get_hostname (& String); ZeroMemory (HostName, 2 * MAX_PATH); lstrcpy (HostName, _bstr_t (String) ); If (lstrlen (hostname) {m_linkslist.setitemtext (i, 1, hostname); log (hostname); log ("/ r / n");}}}}}}}}}}}}}}}}}}} This program is in VC7 Compilation under WinXP, please see the source code in detail! Tanxin79@163.net, thank you reading, the article source code is as follows: http://www.vchelp.net/asp/ibr_upload/543.rar

转载请注明原文地址:https://www.9cbs.com/read-27165.html

New Post(0)