excel抓取网页数据(我对Google表格抓取了解不多我无法正确获取数据(图) )
优采云 发布时间: 2022-03-12 18:20excel抓取网页数据(我对Google表格抓取了解不多我无法正确获取数据(图)
)
用户名
我应该如何抓取这个页面,具体需要表中提到的ROE数?
我在 Excel 中使用了以下代码。我对 Google 表格抓取了解不多
Sub FetchData()
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.bseindia.com/stock-share-price/asian-paints-ltd/asianpaint/500820/", Destination:=Range( _
"$A$1"))
.Name = "www"
.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
End Sub
我无法正确获取数据。
有什么建议/帮助吗? ROE图是必须的,其余的不需要。
QHarr
使用页面可以更快地使用其 API。您可以使用 powerquery 来处理 json 响应、json 解析器或只是拆分。如果您想在按钮按下时刷新,请将代码放在标准模块中并链接到按钮。
Option Explicit
Public Sub GetInfo()
Dim s As String, ids(), i As Long
ids = Array(500820, 500312, 500325, 532540)
With CreateObject("MSXML2.XMLHTTP")
For i = LBound(ids) To UBound(ids)
.Open "GET", "https://api.bseindia.com/BseIndiaAPI/api/ComHeader/w?quotetype=EQ&scripcode=" & ids(i) & "&seriesid=", False
.send
s = .responseText
ActiveSheet.Cells(i + 1, 1) = Split(Split(s, """ROE"":""")(1), Chr$(34))(0)
Next
End With
End Sub