SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    phpdom - domdocument() expects at least 1 parameter

    Hi, I'm trying to run this script which will collect the links using xpath.

    I get this error:

    Warning: domdocument() expects at least 1 parameter, 0 given in /home/solas/public_html/scrape.php on line 41
    This points the line:


    $xpath = new DOMXPath($dom);
    PHP Code:
     function storeLink($url,$gathered_from) {
        
    $query "INSERT INTO links (url, gathered_from) VALUES ('$url', '$gathered_from')";
        
    mysql_query($query) or die('Error, insert query failed');
    }

    $target_url "www.ejc2006.net/";
    //$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
    $userAgent 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9';
    echo 
    "before crurl";
    // make the cURL request to $target_url
    $ch curl_init();
    curl_setopt($chCURLOPT_USERAGENT$userAgent);
    curl_setopt($chCURLOPT_URL,$target_url);
    curl_setopt($chCURLOPT_FAILONERRORtrue);
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($chCURLOPT_AUTOREFERERtrue);
    curl_setopt($chCURLOPT_RETURNTRANSFER,true);
    curl_setopt($chCURLOPT_TIMEOUT10);
    $htmlcurl_exec($ch);
    if (!
    $html) {
        echo 
    "cURL error number:" .curl_errno($ch);
        echo 
    "cURL error:" curl_error($ch);
        exit;
    }
    echo 
    "before dom thing";
    // parse the html into a DOMDocument

    $dom = new DOMDocument();

    @
    $dom->loadHTML($html);

    echo 
    "dom is $dom";

    // grab all the on the page
    $xpath = new DOMXPath($dom);
    $hrefs $xpath->evaluate("/root/html/body//a");

    echo 
    "hrefs is $hrefs";



    for (
    $i 0$i $hrefs->length$i++) {
        
    $href $hrefs->item($i);
        
    $url $href->getAttribute(’href’);
        
    storeLink($url,$target_url);
        echo 
    "Link stored: $url";

    I've tried adding a few parameters, but the script ceases ends on the line
    $dom = new DomDocument('');
    with no errors, no further echo's are output etc...

    Is there a setting on my server I need to turn on or am I doing something else wrong?

    Any help appreciated

    James

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    Php Dom

    Hi solaz, welcome to the forums
    The DOM functions are PHP version 5. If you have PHP version 4, use DOM XML instead.

  3. #3
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks

    Hi, thanks for your welcome and prompt response.

    I'm running php 4.4.4 so yea that's it

    I'll research DOM XML as I'm already walking on outskirts of my knowledge here...

    thank


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •