Extract Data from a Web Page - using VBA

无人久伴 提交于 2019-12-23 04:03:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!