Jump to content

PHP web scraping


qiqakotyi

Recommended Posts

Hi all , I'm new to php. I'm trying to scrape the soccer website (http://www.soccerladuma.co.za/leagues/tables) the league tables on it , i have tried to get the element by it and tag name but i'm getting a blank screen.I only get the whole page if when i remove my tag name n tag id code. Please help , see code below that gets the page and plz lead me to how to get that specific league table from this site.

 

 

<?php
 
 
 
// Create a stream so that we can set a User-Agent 
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n" .
              "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13\r\n"
  )
);
$context = stream_context_create($opts);
 
$str = file_get_contents($url, false, $context);
$str = strip_tags($str,"<style>");
$substring = substr($str,strpos($str,"<style"),strpos($str,"</style>")+2);
 
$dom = new DOMDocument();
$dom ->loadHTML($str); //@  is puted to prevent html warnings
$xpath = new DOMXPath($dom);
 
 
    echo "<pre>";
    print_r($dom->textContent);
    echo "<pre>";
 
?
Link to comment
Share on other sites

Hi all , I'm new to php. I'm trying to scrape the soccer website (http://www.soccerladuma.co.za/leagues/tables) the league tables on it ,

Stop. They specifically prohibit you from doing that:

You acknowledge and agree that the material and content contained within the Website is made available for your personal non-commercial use only and that you may download such material and content onto only one computer hard drive for such purpose. Any other use of the material and content of the Website is strictly prohibited. You agree not to (and agree not to assist or facilitate any third party to) copy, reproduce, transmit, publish, display, distribute, commercially exploit or create derivative works of such material and content.

Find another way or a different place to get the information you need.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.