Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: firstchild node

  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    firstchild node

    So i have this code:

    PHP Code:
    <?php

    include("config.php"); 

    $ch curl_init();

    curl_setopt($chCURLOPT_URL'http://operationoffers.com/publishers/login.php?next'); 
    curl_setopt ($chCURLOPT_POSTtrue); 
    curl_setopt ($chCURLOPT_POSTFIELDS'username=markman641&password=***'); 
    curl_setopt ($chCURLOPT_COOKIEJAR'./cookie.txt'); 
    curl_setopt ($chCURLOPT_FOLLOWLOCATIONtrue); 
    curl_setopt ($chCURLOPT_RETURNTRANSFERtrue); 


    // EXECUTE 1st REQUEST (FORM LOGIN) 
    $store curl_exec ($ch); 

    // SET FILE TO DOWNLOAD 
    curl_setopt($chCURLOPT_URL'http://operationoffers.com/publishers/campaigns/expired.php'); 

    // EXECUTE 2nd REQUEST (FILE DOWNLOAD) 
    $content curl_exec ($ch); 
    $start='<table cellpadding='
    $end='</table>'
    $content=substr($content,strpos($content,$start),strrpos($content,$end)-strpos
    ($content,$start)); 
    echo 
    $content;


    $htmldom = new domDocument();
    @
    $htmldom->loadHTML("$content");
    $ids = array();
    $tds $htmldom->getelementsbytagname("td");
    foreach (
    $ids as $id) {
    $ids $td->firstchild->nodeValue;
    }
    print_r($ids);


    // LOG BACK OUT 
    curl_setopt($chCURLOPT_URL'http://operationoffers.com/publishers/logout.php'); 
    $logged_out curl_exec ($ch); 

    // CLOSE CURL 
    curl_close ($ch); 


    ?>
    cURL part works.. however the main part doesnt. All i get is "Array ( )"
    What is wrong with this?


    Basically all im trying to do is select the first TD in each TR
    Last edited by markman641; 03-30-2012 at 08:36 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Take the supressing @ off of $htmldom->loadHTML call. Does it toss an error?

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Yes, it gives:

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: misplaced <head> tag in Entity, line: 34 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 91 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 116 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 116 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 117 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 117 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 134 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 134 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 136 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 136 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 138 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 138 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 140 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 140 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 142 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 142 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 551 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 551 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: no name in Entity, line: 552 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 552 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 600 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 601 in /home/moneyeve/public_html/expiredbot.php on line 33

    Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 602 in /home/moneyeve/public_html/expiredbot.php on line 33
    Array ( )
    btw line 33 is @$htmldom->loadHTML("$content"); (i added in php error reporting code at top)
    Last edited by markman641; 03-30-2012 at 08:45 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    While the HTML itself is invalid, for an entity ref like this I wouldn't expect an issue.
    After the fetch on getElementsByTagName, see how many children are returned:
    PHP Code:
    print $tds->length
    Is that above zero?

    Also, I just noticed here, and this is likely the issue assuming $tds is > 0:
    PHP Code:
    foreach ($ids as $id) {
    $ids $td->firstchild->nodeValue;

    Ya, $ids is currently 0 in length. Iterating it is useless. I'd assume that this should be:
    PHP Code:
    foreach ($tds AS $td)
    {
        
    $ids[] = $td->firstChild->nodeValue;

    Although I'm not sure what the structure of said td's are, so I have to assume that that access will work.

  • Users who have thanked Fou-Lu for this post:

    markman641 (03-31-2012)

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fou-Lu View Post
    While the HTML itself is invalid, for an entity ref like this I wouldn't expect an issue.
    After the fetch on getElementsByTagName, see how many children are returned:
    PHP Code:
    print $tds->length
    Is that above zero?

    Also, I just noticed here, and this is likely the issue assuming $tds is > 0:
    PHP Code:
    foreach ($ids as $id) {
    $ids $td->firstchild->nodeValue;

    Ya, $ids is currently 0 in length. Iterating it is useless. I'd assume that this should be:
    PHP Code:
    foreach ($tds AS $td)
    {
        
    $ids[] = $td->firstChild->nodeValue;

    Although I'm not sure what the structure of said td's are, so I have to assume that that access will work.
    that returned all TD's..

    here is page source:
    http://pastebin.com/AExWZj4R

    im trying to get the id's

    Or instead of doing all that we can just make it select arrays 1,6,11 ect (every 5th array starting from 1)
    Last edited by markman641; 03-30-2012 at 10:32 PM.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    XPath could probably do that, but I don't know what version is required so PHP may not support it.
    Why not just fetch the entire tr record, and then pull only the first td off of the associated entries? Alternatively, PHP can add only every 5th element using:
    PHP Code:
    $i 0;
    foreach (
    $tds AS $td)
    {
        if (
    $i++ % == 0)
        {
            
    $ids[] = $td->firstChild->nodeValue;
        }
    }  
    // Or
    $iSize $tds->length;
    for (
    $i 0$i $iSize$i += 5)
    {
        
    $ids[] = $tds->item($i)->firstChild->nodeValue;

    Try one of those.

  • Users who have thanked Fou-Lu for this post:

    markman641 (03-31-2012)

  • #7
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fou-Lu View Post
    XPath could probably do that, but I don't know what version is required so PHP may not support it.
    Why not just fetch the entire tr record, and then pull only the first td off of the associated entries? Alternatively, PHP can add only every 5th element using:
    PHP Code:
    $i 0;
    foreach (
    $tds AS $td)
    {
        if (
    $i++ % == 0)
        {
            
    $ids[] = $td->firstChild->nodeValue;
        }
    }  
    // Or
    $iSize $tds->length;
    for (
    $i 0$i $iSize$i += 5)
    {
        
    $ids[] = $tds->item($i)->firstChild->nodeValue;

    Try one of those.
    OMG THANK YOU SO MUCH. (the first one worked)


  •  

    Tags for this Thread

    Posting Permissions

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