将网页源代码下载到工作表

我正在尝试将yahoo.com的网页源代码下载到我的Excel表格中。

我没有设法build立一个代码。 我的代码(下面提到)正在下载网页文字NOT来源:

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 

使用微软的XMLfunction

在VBA编辑器中的Tools / References中激活Microsoft XML v3.0 (如果你在2010及以上,则为6),然后像下面这样启动你的代码:

  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)) 

然后,您可以将线条逐行写入到工作表中,或者更快地将拆分值提供给数组并将其发送到工作表中。

我用它来parsing内存中的HTML,并从网页上下载我想要的数据。 HTH