PHP Web爬网程序返回“未识别的偏移量1”错误

时间:2017-02-08 10:35:58

标签: php web-crawler

我有这个脚本,我尝试从网站中提取链接和文本并将其发布到我的页面中。虽然它的工作就像魅力,但它也在顶部显示错误为unidentified offset 1。 帮我把它弄出来..

代码如下:

<?php

function get_data($url) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_URL,$url);

    $result=curl_exec($ch);

    curl_close($ch);

    return $result;

}

$returned_content = get_data('http://www.usmle-forums.com/usmle-step-1-forum/');

$first_step = explode( '<tbody id="threadbits_forum_26">' , $returned_content );

$second_step = explode('</tbody>', $first_step[1]);

$third_step = explode('<tr>', $second_step[0]);

// print_r($third_step);

foreach ($third_step as $element) {

    $child_first = explode( '<td class="alt1"' , $element );

    $child_second = explode( '</td>' , $child_first[1] );

    $child_third = explode( '<a href=' , $child_second[0] );

    $child_fourth = explode( '</a>' , $child_third[1] );

    echo $final = "<a href=".$child_fourth[0]."</a></br>";

}

?>
$child_second = explode( '</td>' , $child_first[1] );行的

错误 和行$child_fourth = explode( '</a>' , $child_third[1] );

任何帮助表示赞赏..

0 个答案:

没有答案