不能小瞧了仍和一种语言
下面是一个vba写的爬虫,运用到了js和html的知识
Sub getHistortyWeInfo() Dim arr, brr(1 To 1000, 1 To 9) Dim js, slen As Byte, i%, m%, n% Dim rowMax% Set js = CreateObject("scriptcontrol") js.Language = "jscript" arr = Array("ymd", "bWendu", "yWendu", "tianqi", "fengxiang", "fengli", "aqi", "aqiInfo", "aqiLevel") For j = 5 To 11 j = IIf(j >= 10, j, "0" & j) With CreateObject("Msxml2.XMLHTTP") .Open "GET", "http://tianqi.2345.com/t/wea_history/js/2016" & j & "/54527_2016" & j & ".js", False .send strText = StrConv(.responseBody, vbUnicode, &H804) End With js.addcode strText slen = js.Eval("weather_str.tqInfo.length") For i = 0 To slen - 1 m = 1 For Each k In arr brr(n + 1, m) = js.Eval("weather_str.tqInfo[" & i & "]." & k & "") m = m + 1 Next n = n + 1 Next Next Sheet1.[A1].Resize(1, 9) = Array("日期", "最高气温", "最高气温", "天气", "风向", "风力", "空气质量指数", "aqiInfo", "aqiLevel") rowMax = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row + 1 Sheet1.Cells(rowMax, 1).Resize(UBound(brr), 9) = brr End Sub
网页:http://tianqi.2345.com/wea_history/58321.htm