问题
Using VBA, I need to extract data from webpage http://emops.tse.com.tw/t21/sii/t21sc03_2011_9_e.htm
I am able to fetch all the data using following code:
With ActiveSheet.QueryTables.Add(Connection:="URL;http://emops.tse.com.tw/t21/sii/t21sc03_2012_2_e.htm", Destination:=Range("$A$1"))
.Name = "67083361_zpid"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
But the problem is I don't want data from whole page. I want data from the table where Industry name is Electron (It is the last table in this case)
Any trick for the same please?
回答1:
Change:
.WebSelectionType = xlEntirePage to .WebSelectionType = xlSpecifiedTables
Add:
.WebTables = "2" below .WebFormatting = xlWebFormattingNone
'You will have to use trial and error with the "2" to find the exact table you are wanting to grab
来源:https://stackoverflow.com/questions/13932393/extract-data-from-a-web-page-using-vba