2017-02-26 6 views
0

初心者からの質問です。私は、ウェブページからスクラップ情報をスクリーニングする方法について、YouTubeのウェブシリーズに従っています。目標は、これを私が持っている社内アプリケーションに使用できるようにすることです。単に空白のWebページにテキスト値を表示するだけです。しかし、2日後に私はまだVBで単純な関数呼び出しを行うことができない理由を理解できません。これまでに行ったことは、私のフォーム上の 'Private Sub CommandButton1_Click()'ボタンをクリックすると、コンパイルエラーが発生します。ここでVisual Basic - シンプルなWeb Scraper

は、ボタンのコードです:ここで

Private Sub CommandButton1_Click() 
'FirstMacro 

    Set objIE = CreateObject("InternetExplorer.Application") 
    objIE.Top = 0 
    objIE.Left = 0 
    objIE.Width = 800 
    objIE.Height = 600 
    objIE.AddressBar = 0 
    objIE.StatusBar = 0 
    objIE.Toolbar = 0 
    objIE.Visible = True 'We will see the window navigation' 

    objIE.Navigate ("http://www.google.com") 
    TextBox4.Text objIE.Document.body.innerHTML 
End Sub 

は、クラスのコードです:

Public Function FirstMacro() 
'the_start: 

    Set objIE = CreateObject("InternetExplorer.Application") 
    objIE.Top = 0 
    objIE.Left = 0 
    objIE.Width = 800 
    objIE.Height = 600 
    objIE.AddressBar = 0 
    objIE.StatusBar = 0 
    objIE.Toolbar = 0 
    objIE.Visible = True 'We will see the window navigation' 

    'MsgBox.Err.Number 

    'On Error Resume Next 
     'MsgBox.objIE.Document.body.innerHTML 
     'If Err.Number > 0 Then 
      'objIE.Quit 
      'Set objIE = Nothing 
      'GoTo the_start: 
     'End If 

    objIE.Navigate ("http://www.google.com") 

    'Do 
     'DoEvents 
    'Loop Until objIE.ReadyState = 4 

    TextBox4.Text objIE.Document.body.innerHTML 
End Function 

そして、これは私は次のようだシリーズです:https://www.youtube.com/watch?v=Blls6GrCBCY&index=12&list=PL6OYc4rwKjcOu3UL7LYpvO_S2waYO-hVU

感謝騒ぎを助けるために。

enter image description here

答えて

0

あなたは、おそらくこのような何かを試してみてください。

Sub DumpData() 

Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 

URL = "http://finance.yahoo.com/q?s=sbux&ql=1" 

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

RowCount = 1 

With Sheets("Sheet1") 
    .Cells.ClearContents 
    RowCount = 1 
    For Each itm In IE.document.all 
     .Range("A" & RowCount) = itm.tagname 
     .Range("B" & RowCount) = itm.ID 
     .Range("C" & RowCount) = itm.classname 
     .Range("D" & RowCount) = Left(itm.innertext, 1024) 

     RowCount = RowCount + 1 
    Next itm 
End With 
End Sub 

次に、各URLで何を処理しているかを確認する必要があります。