使用 Beautiful Soup 显示来自 onmouseover 属性的文本

Displaying text from onmouseover attribute with Beautiful Soup

这个问题的不同版本已经被问到:

基本上我想要做的是从鼠标悬停时显示的 table 单元格中获取文本,如下图所示。我在 Python 中编码并使用 Beautiful Soup

我可以使用 Beautiful Soup 成功获取 onmouseover 属性:

<td class="right odds down"><div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','357osx2s5a4x0x7ot9r',2,event,0,1)">+340</div></td>  

<div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','357osx2s5a4x0x7ot9r',2,event,0,1)">+340</div>

我的问题是。如何使用属性获取文本(初始奇数):

onmouseover="page.hist(this,'P-0.00-0-0','357osx2s5a4x0x7ot9r',2,event,0,1)

非常感谢任何帮助。

好的答案实际上是使用 Selenium webdriver 获取信息。 例如,如果我们想从 bwin 中获得初始赔率,即赔率数据中的第 8 行 -table: 它的 x 路径是:

 "//*[@id =" + '"odds-data-table"' + "]/div[1]/table/tbody/tr[8]/td[2]")

我们可以通过首先将鼠标悬停在它上面并获取这样的信息来检索初始奇数数据:

 initial_odd_data = driver.find_element_by_xpath("//*[@id =" + '"odds-data-table"' + "]/div[1]/table/tbody/tr[8]/td[2]")
hov = ActionChains(driver).move_to_element(initial_odd_data)
hov.perform()
data_in_the_bubble = driver.find_element_by_xpath("//*[@id='tooltiptext']")
hover_data = data_in_the_bubble.get_attribute("innerHTML")