1

I'm trying to scrape the site inside the code but I would it in table format.

$url='http://www.arbworld.net/en/moneyway';
    libxml_use_internal_errors( true );
    $dom=new DOMDocument;
    $dom->validateOnParse=false;
    $dom->recover=true;
    $dom->strictErrorChecking=false;
    $dom->loadHTMLFile( $url );
    libxml_clear_errors();


    $xp=new DOMXPath( $dom );
    $col=$xp->query('//table[@class="grid"]/tr[@class="belowHeader"]/td');

    if( $col->length > 0 ){
        foreach( $col as $node )echo $node->textContent;
    }

Now the output is this:

Romanian Liga I22.Dec 18:00:00 FCSBUniversitat2.063.33.999.9 %€ 2070.1 %€ 00 %€ 0€ 207 22.Dec 18:00:00 Italian Serie A22.Dec 11:30:00 AtalantaAC Milan1.8844.499.7 %€ 21 5580.1 %€ 170.2 %€ 46€ 21 622 22.Dec 11:30:00 English League 221.Dec 15:0 0:00

1 Answer 1

1

You should retrieve the rows instead of the columns (without the /td at the end), then simply put everything into an HTML table, with one <tr> for each row:

<?php
// your current code

$xp = new DOMXPath($dom);
$rows = $xp->query('//table[@class="grid"]/tr[@class="belowHeader"]');
?>

<table>
  <tbody>
  <?php foreach ($rows as $row): ?>
    <tr>
    <?php foreach ($row->childNodes as $col): ?>
      <?php if ($col->getAttribute('style') !== 'display:none'): ?>
        <?php foreach ($col->childNodes as $colPart): ?>
          <?php if ($colText = trim($colPart->textContent)): ?>
          <td><?= $colText ?></td>
          <?php elseif ($colPart instanceof DOMElement && $colPart->tagName === 'a'): ?>
            <?php
            $href = $colPart->getAttribute('href');
            if (strpos($href, 'javascript') !== 0):
            ?>
            <td><?= $colPart->getAttribute('href') ?></td>
            <?php endif ?>
          <?php endif ?>
        <?php endforeach ?>
      <?php endif ?>
    <?php endforeach ?>
    </tr>
  <?php endforeach ?>
  </tbody>
</table>
Sign up to request clarification or add additional context in comments.

9 Comments

Great! The last thing. How can I separate this: "80.9 %€ 245 063" and insert in two differents columns?
@FilippoSchiera Check my last edit. Splitting the original columns into their children nodes should do the trick.
Great for second time. The last last last thing. In last table of website, there is a column that contains an image inside href --> <a href="ads.betfair.com/…" rel="nofollow" target="_blank"><img src="arbworld.net/flags/chart.png" alt="odds stats"></a>
I would to scrape the redirecturl=***betfair.com/exchange/football/…*** After that we can also close the discussion. Thank you very very much :)
@FilippoSchiera I made another edit. This is getting a little bit too specific now though. I'll let you handle the rest.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.