小白求助帖
vba吧
全部回复
仅看楼主
level 1
2020再见 楼主
Sub GetAllValuesFromTbody()
Dim http As Object
Dim html As Object
Dim tableElement As Object
Dim rowElements As Object
Dim cellElement As Object
Dim i As Integer, j As Integer
Dim cellText As String
' Create XMLHTTP object
Set http = CreateObject("MSXML2.XMLHTTP")
' Send HTTP GET request to the website
http.Open "GET", "http://quote.eastmoney.com/SZ000010.html", False
http.send
' Create HTMLDocument object
Set html = CreateObject("HTMLFILE")
' Load the response text into HTMLDocument object
html.body.innerHTML = http.responseText
' Get the table containing the stock prices
Set tableElement = html.getElementsByClassName("quote2l_cr2_c mt10")(0).getElementsByClassName("sider_brief")(0).getElementsByClassName("t1")(0).getElementsByTagName("tbody")(0)
' Get all rows within the tbody
Set rowElements = tableElement.getElementsByTagName("tr")
' Loop through all rows and cells to get their text
For i = 0 To rowElements.Length - 1
For j = 0 To rowElements(i).getElementsByTagName("td").Length - 1
cellText = rowElements(i).getElementsByTagName("td")(j).innerText
' Write the cell text to the worksheet, starting from A1
ThisWorkbook.Sheets(1).Cells(i + 1, j + 1).Value = cellText
Next j
Next i
End Sub
2024年06月26日 02点06分 1
level 1
2020再见 楼主
想抓取网站这个板块到表格里,但是只抓到了文字,后边的数值没给我显示出来
2024年06月26日 02点06分 2
level 1
2020再见 楼主
网站里是这样的
2024年06月26日 02点06分 3
1