需要正则表达式解决方案来废弃

时间:2016-08-08 13:42:00

标签: php simple-html-dom

我试图在每页45个问题的基础上废弃堆栈溢出的php最新问题。我正在使用 Simple_html_dom 进行解析。我差不多完成但是我无法抓住问题的 no of answers 的值,因为他们正在使用两个单独的div标签。下面是要检查的代码链接,我还附上了执行代码所提供内容的屏幕截图链接。

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>&nbsp&nbspAsked:&nbsp'.$time.'Vote:'.$vote.'View:'.$views.'Answers: '.'<br><br>';
}

Scraped image

在图片中你可以看到答案:“这里我想得到一个问题得到的答案数量” 寻找simple_html_dom的解决方案,虽然正则表达式的答案也可以使用

由于

0 个答案:

没有答案
相关问题