我怎样才能find使用VBA的onmouseover元素?

我试图刮一个网站,有一个元素,如果你将鼠标移到它上面,它会在泡泡中显示一些信息。 我使用VBA来刮页面,但我不知道如何find具体的元素。

看看网页的来源,我得到这个:

<td class="right odds up"> <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-00','1q3cfx2rrhkx0x3jtah',381,event,0,1)" 

提供一些细节,以下是我想要抓取的页面: 匹配页面。 当您将鼠标移动到箭头上时,矩形会显示一些内容。 这就是我想要得到的。

我的代码:

 Private Sub CommandButton6_Click() the_start: Dim objIE As Object Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True On Error Resume Next objIE.Navigate ("http://www.oddsportal.com/baseball/usa/mlb-2014/arizona-diamondbacks-st-louis-cardinals-jeOoAP9r/") Do DoEvents If Err.Number <> 0 Then objIE.Quit Set objIE = Nothing GoTo the_start: End If Loop Until objIE.ReadyState = 4 objIE.Document.all.Item Dim js As Variant js = page.hist(this,P-0.00-0-0,1q3cfx2rrhkx0x3jtah,381,event,0,1) ??? Call objIE.Document.parentWindow.execScript(js, "JavaScript") ??? MsgBox "objIE.js" End Sub 

考虑一下这个例子:

 Option Explicit Sub Test() Dim objIE, colTdNodes, i, objTdNode, objDivNode, strTooltipContent, objDispNode ' open the page Set objIE = CreateObject("InternetExplorer.Application") With objIE .Visible = True .Navigate "http://www.oddsportal.com/baseball/usa/mlb-2014/arizona-diamondbacks-st-louis-cardinals-jeOoAP9r/" ' wait until IE and the page are ready Do While .Busy Or Not .readyState = 4: DoEvents: Loop ' wait until the DOM is ready Do Until .document.readyState = "complete": DoEvents: Loop ' wait until the table is ready Do While TypeName(.document.getElementById("odds-data-table")) = "Null": DoEvents: Loop End With ' below is an example how to retrieve tooltips content ' get table target cells nodes collection Set colTdNodes = objIE.document.getElementsByClassName("right odds") ' loop through each cell in collection For i = 0 To colTdNodes.Length - 1 ' choose the cell from collection Set objTdNode = colTdNodes(i) ' get div node from the cell Set objDivNode = objTdNode.ChildNodes.Item(0) ' get the tooltip content strTooltipContent = GetTooltipContent(objDivNode) ' create new div node to display tooltip content Set objDispNode = objIE.document.createElement("div") ' add the created node into the cell objTdNode.appendChild objDispNode ' set id and style objDispNode.ID = "tooltip" & i objDispNode.Style.Background = "#ddd" objDispNode.Style.padding = "5px" objDispNode.Style.margin = "5px" ' display the tooltip content in the node objDispNode.innerHtml = strTooltipContent Next ' hide the last tooltip objIE.document.parentWindow.execScript "delayHideTip();", "javascript" End Sub Function GetTooltipContent(objNode) Dim objEventMouseOver, objTipNode, objDocument ' get document object Set objDocument = objNode.OwnerDocument ' create mouse event object Set objEventMouseOver = objDocument.createEvent("MouseEvents") ' setup mouseover event objEventMouseOver.initMouseEvent "mouseover", True, True, objDocument.parentWindow, 1, 12, 345, 7, 220, False, False, True, False, 0, "" ' send mouseover event to the div node ' support for dispatchEvent was added in IE9 objNode.dispatchEvent objEventMouseOver ' retrieve appeared tooltip node Set objTipNode = objDocument.getElementById("tooltiptext") ' get tooltip html content GetTooltipContent = objTipNode.innerHtml End Function