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?
you'll need login (through php) see relevant information. isn't straightforward , require work.
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];
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
Post a Comment