PHP简单的HTML DOM解析器在使用str_get_html()之后找不到元素;

时间:2015-12-29 18:42:59

标签: php domparser

我正在使用PHP Simple HTML DOM Parser从其他网站收集一些文本。当我使用file_get_html($ url)时,我收到错误消息“消息:file_get_contents(http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html):无法打开流:HTTP请求失败!HTTP / 1.1 416请求的范围不满意”

所以我可以使用str_get_html($ url)并获得一个返回但我之后找不到任何元素。这是我的代码:

$data['yb_data_reviews'] = ''; 
    $yb_reviews[] = '';
    $yb_url = 'http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html';
    if($yb_url){
        $yb_dom = str_get_html($yb_url);
        foreach($yb_dom->find('div.detailItem') as $yb_review) {
            $item['author'] = $yb_review;
            $yb_reviews[] = $item;
        }
        $data['yb_data_reviews'] = $yb_reviews;
    }
    print_r($data['yb_data_reviews']);

我的回报是空白的。如果我只返回$ yb_dom,那么我得到:

simple_html_dom Object ( [root] => simple_html_dom_node Object ( [nodetype] => 5 [tag] => root [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object *RECURSION* [_] => Array ( [4] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) ) [parent] => [_] => Array ( [0] => -1 [1] => 2 ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 5 [tag] => root [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object *RECURSION* [_] => Array ( [4] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) ) [parent] => [_] => Array ( [0] => -1 [1] => 2 ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) [1] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object ( [nodetype] => 5 [tag] => root [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object *RECURSION* ) [parent] => [_] => Array ( [0] => -1 [1] => 2 ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) [_] => Array ( [4] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) ) [callback] => [lowercase] => 1 [original_size] => 71 [size] => 71 [pos:protected] => 71 [doc:protected] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html [char:protected] => [cursor:protected] => 2 [parent:protected] => simple_html_dom_node Object ( [nodetype] => 5 [tag] => root [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object *RECURSION* [_] => Array ( [4] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) ) [parent] => [_] => Array ( [0] => -1 [1] => 2 ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) [noise:protected] => Array ( ) [token_blank:protected] => [token_equal:protected] => =/> [token_slash:protected] => /> [token_attr:protected] => > [_charset] => UTF-8 [_target_charset] => UTF-8 [default_br_text:protected] => [default_span_text] => [self_closing_tags:protected] => Array ( [img] => 1 [br] => 1 [input] => 1 [meta] => 1 [link] => 1 [hr] => 1 [base] => 1 [embed] => 1 [spacer] => 1 ) [block_tags:protected] => Array ( [root] => 1 [body] => 1 [form] => 1 [div] => 1 [span] => 1 [table] => 1 ) [optional_closing_tags:protected] => Array ( [tr] => Array ( [tr] => 1 [td] => 1 [th] => 1 ) [th] => Array ( [th] => 1 ) [td] => Array ( [td] => 1 ) [li] => Array ( [li] => 1 ) [dt] => Array ( [dt] => 1 [dd] => 1 ) [dd] => Array ( [dd] => 1 [dt] => 1 ) [dl] => Array ( [dd] => 1 [dt] => 1 ) [p] => Array ( [p] => 1 ) [nobr] => Array ( [nobr] => 1 ) [b] => Array ( [b] => 1 ) [option] => Array ( [option] => 1 ) ) )

我做错了什么我不能使用str_get_html()返回任何元素?任何帮助表示赞赏。感谢。

0 个答案:

没有答案