简体   繁体   中英

How Can I get values into html tags using Simple HTML Dom?

I am scraping some values from a table but I have problem to get values from data-odd ("odds" and "odds best betrate" as Class) into td tags.

I will post code:

<tr class="first-row">
    <td class="first-cell tl">
        <a href="../matchdetails.php?matchid=dGifTQkE" onclick="win(this.href, 560, 500, 0, 1); return false;">Kortrijk - St. Truiden</a>
    </td>
    <td class="result">
        <a href="../matchdetails.php?matchid=dGifTQkE" onclick="win(this.href, 560, 500, 0, 1); return false;">3:0</a>
    </td>
    <td class="odds best-betrate" **data-odd="1.72"**></td>
    <td class="odds" **data-odd="3.61"**></td>
    <td class="odds" **data-odd="4.76"**></td>
    <td class="last-cell nobr date">20.02.2016</td>
</tr>
<tr class="strong">
    <td class="first-cell tl">
        <a href="../matchdetails.php?matchid=ADWJ4sDD" onclick="win(this.href, 560, 500, 0, 1); return false;">Lokeren - Genk</a>
    </td>
    <td class="result">
        <a href="../matchdetails.php?matchid=ADWJ4sDD" onclick="win(this.href, 560, 500, 0, 1); return false;">0:0</a>
    </td>
    <td class="odds" **data-odd="3.11"**></td>
    <td class="odds best-betrate" **data-odd="3.31"**></td>
    <td class="odds" **data-odd="2.25"**></td>
    <td class="last-cell nobr date">20.02.2016</td>
</tr>

I know how I can get values between tags and I got them using Simple HTML Dom, but I really don't know how I can get values about "data-odd. In my code you can see bold values that I want to get.

Thanks :)

EDIT: Now I got this result (see picture below): enter image description here

I want that values together the others values, example:

21.02.2016 Waasland-Beveren - Anderlecht 1:0 5.96 4.20 1.51

21.02.2016 Waregem - KV Mechelen 2:3 1.83 3.71 3.98

Thanks Again!

EDIT2: This is my code:

    <?php
include('../simple_html_dom.php');

$html = file_get_html('http://www.betexplorer.com/soccer/belgium/jupiler-league/results/');


foreach($html->find('td') as $e) {
    echo $e->innertext . '<br>';

 }   


foreach( $html->find('td[data-odd]') as $td )
{
    echo $td->attr['data-odd'].PHP_EOL;
}
?>

As mentioned in the comments, data-odd is an attribute of node, so to retrieve its value with simple_html_dom you have to use this syntax:

foreach( $html->find('td[data-odd]') as $td )
{
    echo $td->attr['data-odd'].PHP_EOL;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM