[VBA] Internetexplorer.document.innertext(加圖)

作者: Metal5566 (咩陀56)   2016-09-11 14:35:32
※ [本文轉錄自 Office 看板 #1NrFgTDP ]
作者: Metal5566 (咩陀56) 看板: Office
標題: [問題] Internetexplorer.document.innertext
時間: Sun Sep 11 14:32:58 2016
(若是和其他不同軟體互動之問題 請記得一併填寫)
軟體:
版本:excel office 2010
已新增內容
http://imgur.com/a/oGFYj 這是有問題的CODE和結果
網頁是 http://www.oddsportal.com/
然後進去賽事的頁面 有電視圖示的就是SCRIPT所在
http://imgur.com/a/vNo3q 如圖
我有問到是說 innertext 是把其下標籤的innertext也算
所以TABLE標籤或甚麼的裡面會有SCRIPT標籤的INNERTEXT
想知道怎麼避免不要抓到那段SCRIPT
有用excel在網路抓取資料的需求,在網路上找的了這段code,但是把所有標籤抓下來之後在innertext 儲存格內會有script
另外有找到也是別人的檔案,code大同小異但他的innertext內就不會有script
vba是看書自學的,網頁相關的知識也比較薄弱,想請問一下為什麼會這樣,要怎麼解決
謝謝
作者:黄晨
链接:https://www.zhihu.com/question/20460385/answer/71447219
来源:知乎
著作权归作者所有,转载请联系作者获得授权。
Sub getPageInfo()
With CreateObject("internetexplorer.application")
.Visible = True
.Navigate [URL]
While .ReadyState <> 4 Or .Busy
DoEvents
Wend
Set dmt = .Document
For i = 0 To dmt.all.Length - 1
Set htMent = dmt.all(i)
With ActiveSheet
.Cells(i + 2, "A") = htMent.tagName
.Cells(i + 2, "B") = TypeName(htMent)
.Cells(i + 2, "C") = htMent.ID
.Cells(i + 2, "D") = htMent.Name
.Cells(i + 2, "E") = htMent.Value
.Cells(i + 2, "F") = htMent.Text
.Cells(i + 2, "G") = htMent.innerText
End With
Next i
Set r = Nothing
.Quit
End With
MsgBox "获取页面信息成功!"
End Sub

Links booklink

Contact Us: admin [ a t ] ucptt.com