php - Need a regex solution to scrap -
i trying scrap stack overflow's php newest questions on basis of 45 questions per page.i using simple_html_dom parsing. done couldn't scrape values no of answers given question using 2 seperate div tags. below code link check , attaching screenshot link of executed code gives.
include_once('simple_html_dom.php'); function httpget($url) { $ch = curl_init(); curl_setopt($ch,curlopt_url,$url); curl_setopt($ch,curlopt_returntransfer,true); $output=curl_exec($ch); curl_close($ch); return $output; } $count=45; $url ='http://stackoverflow.com/questions/tagged/php?page=1&sort=newest&pagesize='.$count; $parse = httpget($url); $html = str_get_html($parse); for($i=0;$i<=$count;$i++){ $qu=$html->find('a[class=question-hyperlink]', $i)->href; $que='https://stackoverflow.com'.$qu; $question=$html->find('a[class=question-hyperlink]', $i)->plaintext; $link='<a href="'.$que.'">'.$question.'</a>'; $time=$html->find('span[class=relativetime]',$i)->plaintext; $views=$html->find('.views',$i)->plaintext; $vote=$html->find('span[class=vote-count-post]',$i)->plaintext; $stat1=$html->find('div[class=status answered]',$i)->plaintext; echo'<h3>'.$link.'</h3>  asked: '.$time.'vote:'.$vote.'view:'.$views.'answers: '.'<br><br>'; }
in image can see answers: "here wanna number of answers question got" looking solution simple_html_dom, although regex answers work
thanks
Comments
Post a Comment