vb-the simplest way to access Web pages across domains, get a specific frame for processing
The following three methods take time of 130,82,28 microseconds (one second = 1 million microseconds, =1000 milliseconds, 1 milliseconds =1000 microseconds)
Private Sub Command1_Click () Dim Doc2 as Htmldocumentdim Web2 as webbrowser_v1 Set Web2 = Getframeiframelikeurl (WebBrowser1 . Document, "*baidu.com*") Set Web2 = Getframelikeurl (webbrowser1.document, "*baidu.com*") Set Web2 = Findframebyurl ( Webbrowser1.document, "*baidu.com*") If not Web2 are nothing and then Set Doc2 = Web2.document ' MsgBox ' The text in the frames page is: "& Doc2.body.innerTextEnd IfEnd Sub ' Three methods are used in 130,82,28 microseconds (one second = 1 million microseconds, =1000 milliseconds, 1 milliseconds =1000 microseconds) Function Getframeiframelikeurl (Vdoc as HTMLDocument, Likeurl as String) as Webbrowser_v1dim Vtag, tname As String, frameweb as WebB Rowser_v1for Vtag in Vdoc.all tname = vtag.tagname If tname = "IFRAME" Or tname = "FRAME" Then Set frameweb = Vtag If frameweb.locationurl like Likeurl then Set Getframeiframelikeurl = Frameweb Exit Function end If End ifnextend functionfunction getframelikeurl (Vdoc as HTMLDocument, Likeurl as String) as Webbrowser_v1 DiM frameweb as WEBBROWSER_V1, myframes as Object, I as Long Set myframes = Vdoc.getelementsbytagname ("FRAME") for i = 0 to myframes.length-1 Set frameweb = myframes (i) If Frameweb.locationurl as Likeurl Then Set Getframelikeurl = frameweb Exit Function End If Next End Functionfunction Find Framebyurl (Doc as HTMLDocument, Likeurl as String) as Webbrowser_v1 ' Method 2: Get cross-domain web ' Doc for the webbrowser.document ' to be processed by URL This method is to refer to olelib.tlb http://www.mvps.org/emorcillo/download/vb6/tl_ole.zip on Error Resume Next Dim pcontainer as Olelib. IOleContainer Dim Penumerator as Olelib. IEnumUnknown Dim PUnk as Olelib. IUnknown Dim Pbrowser as webbrowser_v1 Set pcontainer = Doc If pcontainer.enumobjects (olecontf_embeddings, PEn Umerator) = 0 Then does while Penumerator.next (1, pUnk) = 0 Set pbrowser = pUnk If pBr Owser. Locationurl like Likeurl Then ' can be here to add conditions to determine the frame, the basic can be based on UOne of the key characters in RL or innerHTML Set findframebyurl = Pbrowser Exit do End If Loop Set penumerator = Nothing end ifdoend:set Pcontainer = Nothing End Function ' 130, 82, 28
vb-the simplest way to access Web pages across domains, get a specific frame for processing