0

There is this website

http://www.oxybet.com/france-vs-iceland/e/5209778/

What I want is to scrape not the full table but PARTS of this table.

For example to only display rows that include sportingbet stoiximan and mybet and I don't need all columns only 1 x 2 columns, also the numbers that are with red must be scraped as is with the red box or just display an asterisk next to them in the scrape can this be done or do I need to scrape the whole table on a database first then query the database?

What I got now is this code I borrowed from another similar question on this forum which is:

<?php

require('simple_html_dom.php');


$html = file_get_html('http://www.oxybet.com/france-vs-iceland/e/5209778/');

$table = $html->find('table', 0);
$rowData = array();


foreach($table->find('tr') as $row) {
// initialize array to store the cell data from each row
$flight = array();

foreach($row->find('td') as $cell) {
    // push the cell's text to the array

    $flight[] = $cell->plaintext;
}
$rowData[] = $flight;
}

echo '<table>';
foreach ($rowData as $row => $tr) {
echo '<tr>'; 
foreach ($tr as $td)
    echo '<td>' . $td .'</td>';
echo '</tr>';
}
echo '</table>';

?>

which returns the full table. What I want mainly is somehow to detect the numbers selected in the red box (in 1 x 2 areas) and display an asterisk next to them in my scrape, secondly I want to know if its possible to scrape specific columns and rows and not everything do i need to use xpath?

I beg for someone to point me in the right direction I spent hours on this, the manual doesn't explain much http://simplehtmldom.sourceforge.net/manual.htm

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
asiawatcher
  • 41
  • 10
  • Not a dupe but a list of alternative html parsers http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php Might be easier to use –  Jul 02 '16 at 23:49
  • It looks like you can get the red numbers with `$tr->find('.neg_diff')` – pguardiario Jul 03 '16 at 00:23
  • hi not the negatives the positives in the red box marked as "best odds" 1,50 – asiawatcher Jul 03 '16 at 00:25

1 Answers1

0

Link is dead. However, you can do this with xPath and reference the cells that you want by their colour and order, and many more ways too.

This snippet will give you the general gist; taken from a project I'm working on atm:

function __construct($URL)
{

    // make new DOM for nodes
    $this->dom = new DOMDocument();

    // set error level
    libxml_use_internal_errors(true);

    // Grab and set HTML Source
    $this->HTMLSource = file_get_contents($URL);

    // Load HTML into the dom
    $this->dom->loadHTML($this->HTMLSource);

    // Make xPath queryable
    $this->xpath = new DOMXPath($this->dom);
}

function xPathQuery($query){
    return $this->xpath->query($query);
}

Then simply pass a query to your DOMXPath, like //tr[1]

  • hi there it returns Fatal error: Using $this when not in object context in /volume1/web/arb/5.php on line 11 – asiawatcher Dec 23 '16 at 16:22
  • __construct("http://www.matchmoney.com.gr/odds-comparison/"); path("/html/body/div[10]/div[2]/div[2]/div/table/tbody/tr[1]/td[2]"); – asiawatcher Dec 23 '16 at 16:24