duanba8173 2016-07-04 14:17
浏览 16

在非对象中调用成员函数find()

I try to scrape some keywords but i get this error . I can't figure it out i think the problem is with Dom when i load from Curl. I try different methods hope you can help me with this.

With just Dom it works but i need to use with curl .

include("simple_html_dom.php");

$lines = file('key.txt', FILE_SKIP_EMPTY_LINES);

foreach ($lines as $key) 
{
    $bla= ucwords($key);
    $in = str_replace(' ','+',$bla);
    $ch = curl_init();
    $url = 'http://www.google.com/search?hl=en&tbo=d&site=&source=hp&q='.$in.'&oq='.$in.'&num=20';
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $html = curl_exec($ch);
    curl_close($ch);
    $dom = new simple_html_dom();
    $html = str_get_html($html);
    @$dom->load($html);
    $i=0;
    $linkObjs = $html->find('h3.r a'); 
    $content = array();

    foreach ($linkObjs as $linkObj) 
    {
        $title = trim($linkObj->plaintext);
        $descr = $html->find('span.st',$i);
        $i++;   
        $content[] = strip_tags($title.$descr);
    }

    var_dump($content);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 怎么改成循环输入删除(语言-c语言)
    • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
    • ¥15 pyqt5tools安装失败
    • ¥15 mmdetection
    • ¥15 nginx代理报502的错误
    • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
    • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
    • ¥100 描述一下元器件的基本功能,pcba板的基本原理
    • ¥15 STM32无法向设备写入固件
    • ¥15 使用ESP8266连接阿里云出现问题