file get contents - Process pages for a certain information using PHP -


for example, wish mine https://stackoverflow.com/privileges/user/3 , data in div <div class="summarycount al">6,525</div> can add reputation local db along usernumber. think can use file_get_contents

 $data = file_get_contents('https://stackoverflow.com/privileges/user/3'); 

how extract required data i.e 6,525 in above example?

  1. you'll need login (through php) see relevant information. isn't straightforward , require work.

  2. you can use *shrugs* regex parse data, or use xml parser php simple html dom parser. regex...:

    preg_match('!<div class="summarycount al">(.+?)</div>!', $contents, $matches); $rep = $matches[1]; 
  3. if scraping so, can use api instead.

code:

$url = 'http://api.stackoverflow.com/1.0/users/3';  $tucurl = curl_init();  curl_setopt($tucurl, curlopt_url, $url);  curl_setopt($tucurl, curlopt_returntransfer, 1);  curl_setopt($tucurl, curlopt_encoding, 'gzip');   $data = curl_exec($tucurl);  $parse = json_decode($data, true); $rep = $parse['users'][0]['reputation'];  echo $rep; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -