• 爬虫


    不能小瞧了仍和一种语言

    下面是一个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

  • 相关阅读:
    蓝桥杯_基础_杨辉三角
    蓝桥杯_基础_数组特征
    蓝桥杯_基础_美丽的图形
    脉象
    词根汇总
    蓝桥杯 入门训练 Fibonacci数列 解析
    制作tomcat重启.bat文件
    day23(023-递归练习)
    day27(027-反射&JDK新特性)
    day25(025-多线程(下)&GUI)
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/10009229.html
Copyright © 2020-2023  润新知