首页 > 代码库 > vb-跨域访问网页最简单方法,获得特定的frame进行处理
vb-跨域访问网页最简单方法,获得特定的frame进行处理
vb-跨域访问网页最简单方法,获得特定的frame进行处理
以下三种方法所用时间为130,82,28 微秒(一秒=100万微秒,=1000毫秒,1毫秒=1000微秒)
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 Is Nothing Then Set Doc2 = Web2.Document 'MsgBox "框架网页中的文字是:" & Doc2.body.innerTextEnd IfEnd Sub'以下三种方法所用时间为130,82,28 微秒(一秒=100万微秒,=1000毫秒,1毫秒=1000微秒)Function GetFrameIframeLikeUrl(Vdoc As HTMLDocument, LikeUrl As String) As WebBrowser_V1Dim Vtag, Tname As String, FrameWeb As WebBrowser_V1For Each 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 Like LikeUrl Then Set GetFrameLikeUrl = FrameWeb Exit Function End If Next End FunctionFunction FindFrameByUrl(Doc As HTMLDocument, LikeUrl As String) As WebBrowser_V1'方法2:按网址得到跨域的web''DOC为要处理的webbrowser.DOCUMENT'这个方法要引用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, pEnumerator) = 0 Then Do While pEnumerator.Next(1, pUnk) = 0 Set pBrowser = pUnk If pBrowser.LocationURL Like LikeUrl Then '可以在这里加条件判断得到指定的frame,基本可以根据url或者innerHTML中的某个关键字符 Set FindFrameByUrl = pBrowser Exit Do End If Loop Set pEnumerator = Nothing End IfDoEnd: Set pContainer = Nothing End Function'130,82,28
vb-跨域访问网页最简单方法,获得特定的frame进行处理
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。