加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb-跨域访问网页最简单方法,获得特定的frame进行处理

发布时间:2020-12-17 07:50:49 所属栏目:百科 来源:网络整理
导读:vb-跨域访问网页最简单方法,获得特定的frame进行处理 以下三种方法所用时间为130,82,28微秒(一秒=100万微秒,=1000毫秒,1毫秒=1000微秒) Private Sub Command1_Click()Dim Doc2 As HTMLDocumentDim Web2 As WebBrowser_V1 Set Web2 = GetFrameIframeLikeUr

vb-跨域访问网页最简单方法,获得特定的frame进行处理

以下三种方法所用时间为130,82,28微秒(一秒=100万微秒,=1000毫秒,1毫秒=1000微秒)

Private Sub Command1_Click()
Dim Doc2 As HTMLDocument
Dim 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.innerText
End If
End Sub
'以下三种方法所用时间为130,28 微秒(一秒=100万微秒,=1000毫秒,1毫秒=1000微秒)


Function GetFrameIframeLikeUrl(Vdoc As HTMLDocument,LikeUrl As String) As WebBrowser_V1

Dim Vtag,Tname As String,FrameWeb As WebBrowser_V1
For 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 If
Next
End Function


Function 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 Function
Function 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 If
DoEnd:
       Set pContainer = Nothing
    
End Function
'130,28

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读