返回列表 上一主題 發帖

[發問] 請教網頁捉取的問題? CreateObject("msxml2.xmlhttp") 的問題?

[發問] 請教網頁捉取的問題? CreateObject("msxml2.xmlhttp") 的問題?

請教網頁捉取的問題? CreateObject("msxml2.xmlhttp") 的問題?
  1. Sub test() '取損益表(年表)網頁
  2. Dim Url, HTMLsourcecode, GetXml, TableG, i, j
  3. Set HTMLsourcecode = CreateObject("htmlfile")
  4. Set GetXml = CreateObject("msxml2.xmlhttp")
  5. Url = "http://kgieworld.moneydj.com/z/zc/zcq/zcqa/zcqa_2330.djhtm"
  6. With GetXml
  7. .Open "GET", Url, False
  8. .send

  9. ' Debug.Print .document.all(0).getElementsByTagName("div")(0).outerHTML
  10.   ' Debug.Print .document.all(0).getElementsByClassName("t11")(0).outerHTML
  11. ' Debug.Print .document.all(0).getElementsByClassName("table-row")(11).outerHTML
  12. '  Debug.Print .document.all(0).getElementsByClassName("t4t1 table-cell")(2).outerHTML
  13.   'Debug.Print .document.all(0).getElementsByClassName("t3n1 table-cell")(0).outerHTML
  14.   'Debug.Print .document.all(0).getElementsByClassName("t3n1 table-cell")(482).outerHTML
  15.   Debug.Print .document.all(0).getElementsByClassName("t3n1 table-cell")(482).innerHTML

  16. Debug.Print "test"
  17. End With
  18. Set HTMLsourcecode = Nothing '釋放記憶體
  19. Set GetXml = Nothing
  20. End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
複製代碼
請教大大,網頁改版,試修改程式,Debug.Print .document.all(0).getElementsByClassName("t3n1 table-cell")(482).innerHTML
用CreateObject("InternetExplorer.Application")可執行,用CreateObject("msxml2.xmlhttp") 會錯誤,請問如何修改,謝謝

我試著一個方法捉表格有更好的方法麻煩大大告知
Sub Test() '取損益表(年表)網頁
Dim Url, HTMLsourcecode, GetXml, TableG, i, j
Set HTMLsourcecode = CreateObject("htmlfile")
Set GetXml = CreateObject("msxml2.xmlhttp")
Url = "http://kgieworld.moneydj.com/z/zc/zcq/zcqa/zcqa_2330.djhtm"
With GetXml
.Open "GET", Url, False
.Send

HTMLsourcecode.body.innerhtml = .Responsetext

' Debug.Print HTMLsourcecode.all.tags("div")(12).innertext
' Debug.Print HTMLsourcecode.all.tags("div")(15).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(15).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(400).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(482).innertext

'For i = 5 To 10
'  Debug.Print HTMLsourcecode.all.tags("div")(i).innertext
' Next i


For j = 0 To 300
  Debug.Print HTMLsourcecode.all.tags("span")(j).innertext
Next j
'
' Debug.Print HTMLsourcecode.all.tags("div")(5).innertext
' Debug.Print HTMLsourcecode.all.tags("div")(6).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(0).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(1).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(2).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(3).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(4).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(5).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(6).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(7).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(8).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(9).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(10).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(11).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(12).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(13).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(14).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(15).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(16).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(17).innertext
' Debug.Print HTMLsourcecode.all.tags("span")(18).innertext




End With
Set HTMLsourcecode = Nothing '釋放記憶體
Set GetXml = Nothing
End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TOP

回復 2# wufonna


    http://forum.twbts.com/viewthrea ... p;extra=&page=2

01 ===>>> #1173

TOP

回復 3# quickfixer


    謝謝 大大
就是這程式,最近網頁又改版了,捉不到 損益表 的質料,之前是 table,現在改為div內,無法捉表格。

TOP

回復 4# wufonna

那個#1173,我只改網址,套用ok喔

   

TOP

回復 3# quickfixer
請大大 可以貼上程式嗎?
我𧥾不到 01 ===>>> #1173
謝謝

TOP

  1. Private Sub GetIncome(ByVal ss As String) '取損益表(年表)網頁
  2. Dim Url, HTMLsourcecode, GetXml, TableG, i, j
  3. Set HTMLsourcecode = CreateObject("htmlfile")
  4. Set GetXml = CreateObject("msxml2.xmlhttp")
  5. Url = "http://kgieworld.moneydj.com/z/zc/zcq/zcqa/zcqa_" & ss & ".djhtm"
  6. With GetXml
  7. .Open "GET", Url, False
  8. .Send

  9. HTMLsourcecode.body.innerhtml = .Responsetext
  10. Set TableG = HTMLsourcecode.all.tags("table")(2).Rows
  11. For i = 0 To TableG.Length - 1
  12. For j = 0 To TableG(i).Cells.Length - 1
  13. 工作表4.Cells(i + 1, j + 1) = TableG(i).Cells(j).innertext
  14. Next j
  15. Next i
  16. End With
  17. Set HTMLsourcecode = Nothing '釋放記憶體
  18. Set GetXml = Nothing
  19. End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
複製代碼
之前的捉不到

TOP

回復 7# wufonna


    f3202大大,在 2019-6-18 07:55  #11 給你的01網址
去網址裡面的2021-12-24 18:11 #1173 的文章copy:@

TOP

回復 8# quickfixer


   找到了  謝謝 大大  我在試看看

TOP

回復 1# wufonna
謝謝 大大 改好了

GetDividend-(2020-01-05).rar (56.16 KB)

TOP

        靜思自在 : 是非當教育,讚美作警惕。
返回列表 上一主題