0

I'm trying to scrape that table in the middle, it's the only thing that I need from this web, and also it's the only thing I can't get from there. after few attempts, I created this little code that scrape ALL the html divs, please tell me what i'm doing wrong and what you think. thanks! (In the bottom: picture of the part from this page that I'm looking for)

<?php
include_once("simple_html_dom.php");
$link = 'http://www.oddsportal.com/soccer/argentina/copa-argentina/colon-santa-fe-ind-rivadavia-bTD4Oj2C/?r=1#1X2;2';

$html = file_get_html($link);
$table = true;
$i = 0;

while ($table)
{
$table = $html->find("div",$i++);
echo $table;    

}
?>

the table

Thanks again :)

3
  • What exactly do you want to scrape from the table? Commented Jun 8, 2017 at 18:17
  • all data (all tr's and td's) but looks like that their is no access to this table and this table only. Commented Jun 8, 2017 at 18:41
  • I updated my answer. Commented Jun 8, 2017 at 19:01

1 Answer 1

1

Updated Answer

Table in the web site that you want to scrape it, puts the table there with ajax calls when the page was loaded. So; when you scrape html, there is no table in there.

You can all simulate their ajax calls but this will be harder for you. Open your network tab on Chrome and analyze all request, when you found the real request that getting the table to the page, scrape it.


Old Answer

I assume that; you scrape the table properly. After that you need a for loop to scrape each div in the table.

foreach($html->find('tr div.l a') as $element) {
   echo $element->href;
}

You should adapt the above code to your code.

Full Code

<?php
  include_once("simple_html_dom.php");
  $link = 'http://www.oddsportal.com/soccer/argentina/copa-argentina/colon-santa-fe-ind-rivadavia-bTD4Oj2C/?r=1#1X2;2';

  $html = file_get_html($link);
  foreach($html->find('tr div.l a') as $element) {
    echo $element->href;
  }
?>
Sign up to request clarification or add additional context in comments.

5 Comments

the problem is that i didn't scrape the table, but thanks, sure ill use this loop after ill success.
@AvivS I'm trying now on my pc now.
How for your opinion is the easiest way to do that? I've tried to analyze the request but without success. it's making sense that its because the ajax, but how can I request the html after ajax loaded?
update: I think the answer is that it's cannot done purely by PHP, ill start reading about phantom js, still, ill be happy to hear more for your opnion.
@AvivS yes. You should search another programming languages and libraries to do this.

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.