2015-06-25 53 views
0

我想製作一個宏獲取器,它首先登錄到網站,然後獲取html表數據。我已經從網站獲取html表格數據,但沒有登錄頁面,但我只在Excel表格中獲得了第一頁數據。我需要獲取表格的所有頁面數據,但首先登錄到網頁。 這裏是從網站獲取html表格數據的代碼。如何使用宏登錄到網站並獲取整個數據html表

Sub Macro1() 
' 
' Macro1 Macro 
' 
    With ActiveSheet.QueryTables.Add(Connection:= _ 
     "URL;https://datatables.net/examples/basic_init/alt_pagination.html" _ 
     , Destination:=Range("$A$1")) 
     .Name = "alt_pagination.html" 
     .FieldNames = True 
     .RowNumbers = False 
     .FillAdjacentFormulas = False 
     .PreserveFormatting = True 
     .RefreshOnFileOpen = False 
     .BackgroundQuery = True 
     .RefreshStyle = xlInsertDeleteCells 
     .SavePassword = False 
     .SaveData = True 
     .AdjustColumnWidth = True 
     .RefreshPeriod = 0 
     .WebSelectionType = xlSelectedTables 
     .WebFormatting = xlWebFormattingNone 
     .WebPreFormattedTextToColumns = True 
     .WebConsecutiveDelimitersAsOne = True 
     .WebSingleBlockTextImport = False 
     .WebDisableDateRecognition = False 
     .WebDisableRedirections = False 
     .Refresh BackgroundQuery:=False 
    End With 
    ActiveWindow.SmallScroll Down:=-36 
End Sub 

回答

0

我已經做了這個分開。第一個宏將通過IE登錄到網站,第二個將獲得整個html表數據。

 Sub Login() 
      Set ie = CreateObject("InternetExplorer.application") 
      ie.Visible = True 
      ie.Navigate ("https://www.facebook.com/?id=" & ActiveCell) 'Enter your website url 
      Do 
       If ie.ReadyState = 4 Then 
        ie.Visible = True 
        Exit Do 
       Else 
        DoEvents 
       End If 
      Loop 
      ie.document.forms(0).all("opername").Value = "myuser" 'Enter UserName 
      ie.document.forms(0).all("password").Value = "mypass" 'Enter Password 
      ie.document.forms(0).submit 

       End With 
     End Sub 

Sub Macro1() 
    With ActiveSheet.QueryTables.Add(Connection:= _ 
     "URL;https://datatables.net/examples/basic_init/alt_pagination.html" _ 
     , Destination:=Range("$A$1")) 
     .Name = "alt_pagination.html" 
     .FieldNames = True 
     .RowNumbers = False 
     .FillAdjacentFormulas = False 
     .PreserveFormatting = True 
     .RefreshOnFileOpen = False 
     .BackgroundQuery = True 
     .RefreshStyle = xlInsertDeleteCells 
     .SavePassword = False 
     .SaveData = True 
     .AdjustColumnWidth = True 
     .RefreshPeriod = 0 
     .WebSelectionType = xlSelectedTables 
     .WebFormatting = xlWebFormattingNone 
     .WebPreFormattedTextToColumns = True 
     .WebConsecutiveDelimitersAsOne = True 
     .WebSingleBlockTextImport = False 
     .WebDisableDateRecognition = False 
     .WebDisableRedirections = False 
     .Refresh BackgroundQuery:=False 
    End With 
End Sub 
相關問題