2017-06-14 6 views
0

WebQueryを動作させようとしていますが、それはできないようです。 私の目標は、Webページのソースコードをスクラップすることです。残念なことに、このサイトには、私のコードが正しく動作しない理由が異なるフレームがあるようです。したがって、フレーム問題を解決するはずのオンラインで見つかったコードを修正しようとしました。問題は、コードがうまくいかないことです。おそらく少し古いようです。誰でも助けてくれますか?VBA - Web Query - multiple Frames

次のコードは、作成時にエラー(objecetが必要): "設定profileFrame .document.getElementById(" profileFrame ")"

ます。Public Sub IE_Automation()

'Needs references to Microsoft Internet Controls and Microsoft HTML Object Library 

Dim baseURL As String 
Dim IE As InternetExplorer 
Dim HTMLdoc As HTMLDocument 
Dim profileFrame As HTMLIFrame 
Dim slotsDiv As HTMLDivElement 

'example URL with multiple frames 
baseURL = "https://www.xing.com/search/members?section=members&keywords=IT&filters%5Bcontact_level%5D=non_contact" 

Set IE = New InternetExplorer 
With IE 
    .Visible = True 

    'Navigate to the main page 

    .navigate baseURL & "/publictrophy/index.htm?onlinename=ace_anubis" 
    While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend 

     'Get the profileFrame iframe and navigate to it 

     Set profileFrame = .document.getElementById("profileFrame") 

     .navigate baseURL & profileFrame.src 
     While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend 

      Set HTMLdoc = .document 
     End With 

     'Display all the text in the profileFrame iframe 

     MsgBox HTMLdoc.body.innerText 

     'Display just the text in the slots_container div 

     Set slotsDiv = HTMLdoc.getElementById("slots_container") 
     MsgBox slotsDiv.innerText 

    End Sub 

幸運を祈り、 アンドレアス

答えて

0

Hummmm、ここで何をしているのか正確には分かりませんが、下のコードを試してみることはできますか?

Option Explicit 

Sub Sample() 
    Dim ie As Object 
    Dim links As Variant, lnk As Variant 
    Dim rowcount As Long 

    Set ie = CreateObject("InternetExplorer.Application") 
    ie.Visible = True 
    ie.navigate "https://www.xing.com/search/members?section=members&keywords=IT&filters%5Bcontact_level%5D=non_contact" 

    'Wait for site to fully load 
    'ie.Navigate2 URL 
    Do While ie.Busy = True 
     DoEvents 
    Loop 

    Set links = ie.document.getElementsByTagName("a") 

    rowcount = 1 

    With Sheets("Sheet1") 
     For Each lnk In links 
     'Debug.Print lnk.innerText 
      'If lnk.classname Like "*Real Statistics Examples Part 1*" Then 
       .Range("A" & rowcount) = lnk.innerText 
       rowcount = rowcount + 1 
       'Exit For 
      'End If 
     Next 
    End With 
End Sub 
+0

こんにちはryguy72とありがとう!残念ながら私はエラー "私たちの範囲"を取得します。私は問題を回避するためにコンテンツをスクラップしてVBA経由でExcelにインポートするために、今はimacros chromeプラグインを使用しています。しかしもちろん、直接的な方法は、適切なやりかたでより便利です。最高の願いAndreas – Andreas

+0

F8を繰り返し押してコードをステップ実行すると、 "our of range"というエラーがどこで発生しますか?どの行がエラーをスローしますか?それは手がかりになるはずです。しかし、私はどこにエラーがあると推測することはできませんか?私は何も疑いがなく、すべてがうまくいった。 – ryguy72