#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Parsing html with DOM parser


    Hi all, i need little help parsing html with dom parser.

    My code is as follows:

    PHP Code:
    <?php
    include('simple_html_dom.php');
    $url "site.com";
    $a "558avb";
    $html = new simple_html_dom();

    $ch curl_init();
    curl_setopt($chCURLOPT_URL,$url);
    curl_setopt($chCURLOPT_FAILONERROR1);
    curl_setopt($chCURLOPT_CONNECTTIMEOUT30);
    curl_setopt($chCURLOPT_USERAGENT,
            
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($chCURLOPT_POSTFIELDS'regmark=' urlencode($a));

    $result curl_exec($ch);
    $html->load($result);
    echo 
    $html->find('<strong>');
    //echo $result;
    curl_close($ch);
    ?>
    Thing is that its not working, it shows me only "Array" after loading the page, any ideas what is wrong?


    Best Regards
    MikkM
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,538
    Rep Power
    595
    Nothing is wrong other than not understanding what 'find' returns. You are getting exactly what you programmed. The 'find' method returns an object (which is represented as an array) not something you can directly echo. Try this:
    PHP Code:
    $content=$html->find('<strong>');
    echo 
    $content->outertext
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by gw1500se
    Nothing is wrong other than not understanding what 'find' returns. You are getting exactly what you programmed. The 'find' method returns an object (which is represented as an array) not something you can directly echo. Try this:
    PHP Code:
    $content=$html->find('<strong>');
    echo 
    $content->outertext
    Now i get error "Trying to get property of non-object" in line
    PHP Code:
    echo $content->outertext
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,538
    Rep Power
    595
    That means 'find' returned an empty object. In other words it did not find the tag. I did not notice it the first time but I am not sure find works with any tag (strong has no attributes) but you need to remove the '<>' from the tag name. You more likely will need to 'find' some other tag like <p> or <div> to get what you want.
    PHP Code:
    $content=$html->find('strong'); 
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo