2015年10月2日 星期五

【Excel VBA】取得某網頁的原始html程式碼。

    Dim web, url, webdata
   
    ThisWorkbook.Worksheets("xxxx").Cells.ClearContents  '清除之前資料
   
    url = "http://xxxxxxxxxxxxxxxxxx"
    Set web = CreateObject("Microsoft.XMLHTTP")
    web.Open "get", url, False
    web.send
    webdata = Split(web.responseText, vbLf)
   
   
    For j = 0 To UBound(webdata)
         ThisWorkbook.Worksheets("xxxx").Cells(j + 1, 1).NumberFormatLocal = "@" '將儲存格設為文字.否則遇到有等號開頭就會出錯'
         ThisWorkbook.Worksheets("xxxx").Cells(j + 1, 1).Value = webdata(j)
    Next




取得html原始碼之後,就可以像python 一樣,拿來爬了。

沒有留言:

張貼留言