用python查找元素文本

dz6r00yl  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(317)

我尝试用python从java元素中查找一些文本。

<div id="allBetsTable" data-gameid="89519742" style="transition-timing-function: cubic-bezier(0.1, 0.57, 0.1, 1); transition-duration: 0ms; transform: translate(0px, 0px) translateZ(0px);"><div class="bet_group_col cols1"><div><div class="bet_group"><div class="bet-title bet-title_justify"><span class="bet-title__star"></span> 
            Match-Ups, 1X2. Duel between Players (Goals)
         <!----></div> <div class="bets betCols3"><div class=""><span data-type="13087" class="bet_type">Match-Up Leigh Griffiths - Jonathan David - Celtic
        <!----> <!----> <!----></span> <span data-coef="3.755" class="koeff"><i>3.755</i></span></div><div class=""><span data-type="13089" class="bet_type">Match-Up Leigh Griffiths - Jonathan David - X
        <!----> <!----> <!----></span> <span data-coef="1.567" class="koeff"><i>1.567</i></span></div><div class=""><span data-type="13088" class="bet_type">Match-Up Leigh Griffiths - Jonathan David - Lille OSC
        <!----> <!----> <!----></span> <span data-coef="3.976" class="koeff"><i>3.976</i></span></div></div></div></div><div><div class="bet_group"><div class="bet-title bet-title_justify"><span class="bet-title__star"></span> 
            Match-Ups, Double Chance. Duel between Players (Goals)
         <!----></div> <div class="bets betCols3"><div class=""><span data-type="13090" class="bet_type">Match-Up Leigh Griffiths - Jonathan David , Double Chance - CelticX
        <!----> <!----> <!----></span> <span data-coef="1.106" class="koeff"><i>1.106</i></span></div><div class=""><span data-type="13092" class="bet_type">Match-Up Leigh Griffiths - Jonathan David , Double Chance - Celtic Lille OSC
        <!----> <!----> <!----></span> <span data-coef="1.931" class="koeff"><i>1.931</i></span></div><div class=""><span data-type="13091" class="bet_type">Match-Up Leigh Griffiths - Jonathan David , Double Chance - Lille OSCX
        <!----> <!----> <!----></span> <span data-coef="1.124" class="koeff"><i>1.124</i></span></div></div></div></div><div><div class="bet_group"><div class="bet-title bet-title_justify"><span class="bet-title__star"></span> 
            Match-Ups, Total. Duel between Players (Goals)
         <!----></div> <div class="bets betCols2"><div class=""><span data-type="13093" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Over (0.5)
        <!----> <!----> <!----></span> <span data-coef="1.686" class="koeff"><i>1.686</i></span></div><div class=""><span data-type="13094" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Under (0.5)
        <!----> <!----> <!----></span> <span data-coef="1.776" class="koeff"><i>1.776</i></span></div><div class=""><span data-type="13093" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Over (1)
        <!----> <!----> <!----></span> <span data-coef="3.456" class="koeff"><i>3.456</i></span></div><div class=""><span data-type="13094" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Under (1)
        <!----> <!----> <!----></span> <span data-coef="1.154" class="koeff"><i>1.154</i></span></div><div class=""><span data-type="13093" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Over (1.5)
        <!----> <!----> <!----></span> <span data-coef="5.32" class="koeff"><i>5.32</i></span></div><div class=""><span data-type="13094" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Under (1.5)
        <!----> <!----> <!----></span> <span data-coef="1.033" class="koeff"><i>1.033</i></span></div></div></div></div><div><div class="bet_group"><div class="bet-title bet-title_justify"><span class="bet-title__star"></span> 
            Match-Ups, Handicap. Duel between Players (Goals)
         <!----></div> <div class="bets betCols2"><div class=""><span data-type="13095" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Handicap Celtic (0)
        <!----> <!----> <!----></span> <span data-coef="1.682" class="koeff"><i>1.682</i></span></div><div class=""><span data-type="13096" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Handicap Lille OSC (0)
        <!----> <!----> <!----></span> <span data-coef="1.781" class="koeff"><i>1.781</i></span></div></div></div></div></div> </div>

我要定位这条线:

<span data-coef="1.686" class="koeff"><i>1.686</i></span></div><div class=""><span data-type="13094" class="bet_type">Match-Up Leigh Griffiths - Jonathan David, Total Goals Under (0.5)

我知道如何使用xpath和css选择器来定位它,但是它在移动(元素有时会改变位置),这就是xpath发生变化的原因。

cmssoen2

cmssoen21#

您可以使用class属性来定位元素:

driver.find_element_by_class_name('koeff')
driver.find_element_by_class_name('bet_type')

相关问题