How to get certain info from webpages using request Python

C45HC0W

Regular Member
Joined
Jan 30, 2019
Messages
430
Reaction score
142
Im working on a python webscrapping script with request and beautiful soup. how do i get the number (4.00) out of this html code: <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','34d55xv498x0x0',80,event,0,1)">4.00</div>
Thank you for any ideas in advance!
Code:
                    <tr class="lo even">
                        <td>
                            <div class="l"><a class="name2" title="Go to 12BET website!" onclick="return !window.open(this.href)" href="/bookmaker/12bet/link/"><span class="blogos l80"></span></a>&nbsp;<a class="name" title="Go to 12BET website!" onclick="return !window.open(this.href)" href="/bookmaker/12bet/link/">12BET</a>&nbsp;&nbsp;</div><span class="ico-bookmarker-info ico-bookmaker-detail"><a title="Show more details about 12BET" href="/bookmaker/12bet/"></a></span><span class="ico-bookmarker-info ico-bookmaker-bonus"><a onmouseout="globals.getBookmaker(80).cancelBonusOver();" xparam="<div class=&quot;bold&quot;>Matched Freebet up to £35!</div><div>Place 6 bets and receive a freebet up to £35!</div>~3" onmouseover="globals.getBookmaker(80).trackBonusOver()" onclick="globals.getBookmaker(80).trackBonusClick();return !window.open(this.href);" href="/bookmaker/12bet/bonus/164"></a></span></td>
                        <td class="right odds up">
                            <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','34d55xv464x0x7mi9j',80,event,0,1)">1.58</div>
                        </td>
                        <td class="right odds up">
                            <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','34d55xv498x0x0',80,event,0,1)">4.00</div>
                        </td>
                        <td class="right odds down">
                            <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','34d55xv464x0x7mi9k',80,event,0,1)">6.00</div>
                        </td>
                        <td class="center info-value"><span>95.3%</span></td>
                        <td onmouseout="delayHideTip()" class="check ch1" xparam="FRESH ODDS<br />(last update %t ago)~2"></td>
                    </tr>
 
Im working on a python webscrapping script with request and beautiful soup. how do i get the number (4.00) out of this html code: <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','34d55xv498x0x0',80,event,0,1)">4.00</div>
Thank you for any ideas in advance!
Code:
                    <tr class="lo even">...

just realized this post was super old...

#PYTHON3

Code:
from bs4 import BeautifulSoup

html_string = '''
<tr class="lo even">
                        <td>
                            <div class="l"><a class="name2" title="Go to 12BET website!" onclick="return !window.open(this.href)" href="/bookmaker/12bet/link/"><span class="blogos l80"></span></a>&nbsp;<a class="name" title="Go to 12BET website!" onclick="return !window.open(this.href)" href="/bookmaker/12bet/link/">12BET</a>&nbsp;&nbsp;</div><span class="ico-bookmarker-info ico-bookmaker-detail"><a title="Show more details about 12BET" href="/bookmaker/12bet/"></a></span><span class="ico-bookmarker-info ico-bookmaker-bonus"><a onmouseout="globals.getBookmaker(80).cancelBonusOver();" xparam="<div class=&quot;bold&quot;>Matched Freebet up to £35!</div><div>Place 6 bets and receive a freebet up to £35!</div>~3" onmouseover="globals.getBookmaker(80).trackBonusOver()" onclick="globals.getBookmaker(80).trackBonusClick();return !window.open(this.href);" href="/bookmaker/12bet/bonus/164"></a></span></td>
                        <td class="right odds up">
                            <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','34d55xv464x0x7mi9j',80,event,0,1)">1.58</div>
                        </td>
                        <td class="right odds up">
                            <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','34d55xv498x0x0',80,event,0,1)">4.00</div>
                        </td>
                        <td class="right odds down">
                            <div onmouseout="delayHideTip()" onmouseover="page.hist(this,'P-0.00-0-0','34d55xv464x0x7mi9k',80,event,0,1)">6.00</div>
                        </td>
                        <td class="center info-value"><span>95.3%</span></td>
                        <td onmouseout="delayHideTip()" class="check ch1" xparam="FRESH ODDS<br />(last update %t ago)~2"></td>
                    </tr>
 
'''
# html as soup object
html_soup = BeautifulSoup(html_string, "html.parser")

# list of " right odds up " one of which contains our target value 4.0
rightodds_list = html_soup.find_all("td", attrs={'class': 'right odds up'})

print(
  "list element 1: {} \n\n\n list element 2: {}".format(
    rightodds_list[0],
    rightodds_list[1])
  )

# not sure what OP's plan was; but with python, literally a zillion ways to do this..
# but i broke down an example..

#stringify target data
target = str(rightodds_list[1])

#parse the string as new bs object
target_soup = BeautifulSoup(target,"html.parser")
target_value = target_soup.find("div")

#profit
print("\n\n\n target value: {}".format(target_value.text))
 
why not using a html parser like beautifulsoup? you could then run queries on it. or it might even give you a xpath or selector interface.
 
Back
Top