我正在尝试将yahoo.com的网页源代码下载到我的excel表中。
我没能造出密码。我的代码(下面提到)是下载网页文本而不是源代码:
With ActiveSheet.QueryTables.Add(Connection:="URL;https://www.yahoo.com/?p=us" _
, Destination:=Range("$A$1"))
.Name = "?p=us"
.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发布于 2015-07-23 12:11:33
使用Microsoft的XML功能
在VBA编辑器中的工具/引用中激活Microsoft、v3.0 (如果您在2010年或更高版本的话),然后启动如下代码:
Dim oXML As New MSXML2.XMLHTTP
Dim xURL As String
Dim uTxt As String
xURL = "https://www.yahoo.com/?p=us"
oXML.Open "GET", xURL, False
oXML.setRequestHeader "Content-Type", "text/xml"
oXML.send
uTxt = oXML.responseText
Codesplit = Split(uTxt, Chr(13))然后,您可以逐行将这些行写入工作表,或者更快地将拆分后的值输入数组并一次发送到工作表。
我使用它来解析内存中的HTML,并只从网页下载我想要的数据。HTH
https://stackoverflow.com/questions/30364872
复制相似问题