2011-10-26 69 views
0

由於某種原因,我沒有得到這個捲曲函數的預期輸出,IF我嘗試print_r out我看到每個節點的所有值,但如果我嘗試將它們分配給我的obj /數組I由於某種原因,最終只收到前兩名。在/ * * /代碼是我的問題,我相信....問題與CURL和XPATH不適當地返回值?

class Scraper { 
    protected $ministers = array(); 
    protected $domain; 

    // Set actions to run when the class is instantiated 
    function __construct($url){ 
     // Set the maximum execution time of the script to unlimited so that it can grab all the ministers if there are a lot of them to scrape 
     set_time_limit(0); 

     // Set the root domain of the URL to concatinate with URLs later 
     $this->domain = explode("/", $url); 
     $this->domain = 'http://' . $this->domain[2]; 

     // Pass the page URL you want to start scraping and start scraping through the section pages 
     $this->getministers($url); 

     echo count($this->ministers) . ' - Done counting ministers items, now adding ministers.<br>'; 

     // Add function here to start adding items in the minister array with ministers to a database 

    } 

    //Start Get ministers 
    private function getministers($url){ 
     // Instantiate cURL to grab the HTML page. 
     $c = curl_init($url); 
     curl_setopt($c, CURLOPT_HEADER, false); 
     curl_setopt($c, CURLOPT_USERAGENT, $this->getUserAgent()); 
     curl_setopt($c, CURLOPT_FAILONERROR, true); 
     curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); 
     curl_setopt($c, CURLOPT_AUTOREFERER, true); 
     curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($c, CURLOPT_TIMEOUT, 10); 

     // Grab the data. 
     $html = curl_exec($c); 

     // Check if the HTML didn't load right, if it didn't - report an error 
     if (!$html) { 
      echo "<p>cURL error number: " .curl_errno($c) . " on URL: " . $url ."</p>" . 
       "<p>cURL error: " . curl_error($c) . "</p>"; 
     } 

     // Close connection. 
     curl_close($c); 

     // Parse the HTML information and return the results. 
     $dom = new DOMDocument(); 
     @$dom->loadHtml($html); 

     $xpath = new DOMXPath($dom); 

     // Get a list of ministers from the section page 
     $ministerList = $xpath->query("//*[@id='site_content_sub']/div[2]"); 

     // Add each minister to the ministers array 
     foreach ($ministerList as $item){ 

     /* shows ALL the values that I'm looking for (50+) */ 
      print_r($item->nodeValue); 

     /* will only grab the first two then stop for some reason?? 
      $this->ministers[] = array(
             'img' => $item->getElementsByTagName('img')->item(0)->getAttribute('src'), 
             'name' => $item->getElementsByTagName('li')->item(1)->nodeValue, 
             'born' => $item->getElementsByTagName('li')->item(2)->nodeValue, 
             'died' => $item->getElementsByTagName('li')->item(3)->nodeValue, 
             'note' => $item->getElementsByTagName('li')->item(4)->nodeValue, 
            ); 
     */ 
     } 
    } 
    // End Get ministers 

    // Start Get Browser User Agent 
    private function getUserAgent(){ 
     // Set an array with different browser user agents 
     $agents = array(
          "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; bgft)", 
          "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; http://bsalsa.com) ; .NET CLR 2.0.50727)", 
          "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Orange 8.0; GTB6.3; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; Embedded Web Browser from: http://bsalsa.com/; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30618; OfficeLiveConnector.1.3; OfficeLivePatch.1.3)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.8) Gecko/20100722 BTRS86393 Firefox/3.6.8 (.NET CLR 3.5.30729; .NET4.0C)", 
          "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US)", 
          "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)", 
          "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7)", 
          "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; InfoPath.3; MS-RTC LM 8; .NET4.0C; .NET4.0E)", 
          "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)", 
          "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)", 
          "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; Tablet PC 2.0; InfoPath.3; .NET4.0C; .NET4.0E)", 
          "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/5.0)", 
          "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)", 
          "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)", 
          "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)", 
          "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", 
          "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.0; Trident/4.0; InfoPath.1; SV1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 3.0.04506.30)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 3.0)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; msn OptimizedIE8;ZHCN)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; InfoPath.3; .NET4.0C; .NET4.0E)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; .NET4.0C; .NET4.0E; Zune 4.7; InfoPath.3)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; Zune 4.0)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; yie8)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; Zune 3.0; MS-RTC LM 8)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; MS-RTC LM 8; Zune 4.0)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8)", 
          "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; FDM; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; .NET CLR 1.1.4322)", 
          "Opera/9.99 (Windows NT 5.1; U; pl) Presto/9.9.9", 
          "Opera/9.80 (J2ME/MIDP; Opera Mini/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/886; U; en) Presto/2.4.15", 
          "Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1", 
          "Opera/9.70 (Linux i686 ; U; zh-cn) Presto/2.2.0", 
          "Opera/9.70 (Linux i686 ; U; en-us) Presto/2.2.0", 
          "Opera/9.70 (Linux i686 ; U; en) Presto/2.2.1", 
          "Opera/9.70 (Linux i686 ; U; en) Presto/2.2.0", 
          "Opera/9.70 (Linux i686 ; U; ; en) Presto/2.2.1", 
          "Opera/9.70 (Linux i686 ; U; ; en) Presto/2.2.1", 
          "Mozilla/5.0 (Linux i686 ; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.70", 
          "Mozilla/4.0 (compatible; MSIE 6.0; Linux i686 ; en) Opera 9.70", 
          "Opera/9.64(Windows NT 5.1; U; en) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux x86_64; U; pl) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux x86_64; U; hr) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux x86_64; U; en-GB) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux x86_64; U; en) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux x86_64; U; de) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux x86_64; U; cs) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; tr) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; sv) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; pl) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; nb) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; Linux Mint; nb) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; Linux Mint; it) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; en) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; de) Presto/2.1.1", 
          "Opera/9.64 (X11; Linux i686; U; da) Presto/2.1.1", 
          "Opera/9.64 (Windows NT 6.1; U; MRA 5.5 (build 02842); ru) Presto/2.1.1", 
          "Opera/9.64 (Windows NT 6.1; U; de) Presto/2.1.1", 
          "Opera/9.64 (Windows NT 6.0; U; zh-cn) Presto/2.1.1", 
          "Opera/9.64 (Windows NT 6.0; U; pl) Presto/2.1.1", 
          "Opera 9.7 (Windows NT 5.2; U; en)", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-HK) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.0; tr-TR) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.0; nb-NO) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.0; fr-FR) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5", 
          "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; zh-cn) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5", 
          "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; de-de) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", 
          "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; da-dk) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", 
          "Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", 
          "Mozilla/5.0 (X11; U; Linux x86_64; en-ca) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.1; ja-JP) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.1; es-ES) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Windows; U; Windows NT 6.0; ja-JP) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_8; ja-jp) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; fr) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; zh-cn) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; ru-ru) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; ko-kr) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; it-it) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/534.1+ (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-au) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; el-gr) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; ca-es) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; zh-tw) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; ja-jp) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; it-it) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; fr-fr) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", 
          "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; es-es) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16" 
         ); 

     return $agents[rand(0, (count($agents)-1))]; 
    } 
    // End Get Browser User Agent 
} 
// End Scraper Class 

如果我運行的節點,只是print_r的他們像上面的輸出:

Rob Dyrdek 06-28-1974 ---- Skateboarding Entrepreneur, Fantasy Factory on MTV Glenn Beck 02-10-1964 ---- Talk Radio Host Mel Blanc 05-30-1908 07-10-1989 Voice Actor Susan Block 09-1-1951 ---- Talkshow Host, Sexologist John Wayne Bobbitt 03-23-1967 ---- Penectomy Survivor Ray Bolger 01-10-1904 01-15-1987 Actor, Appeared in The Wizard of Oz Richard Branson 07-18-1950 ---- Founder of Virgin Enterprises Susie Bright 03-25-1958 ---- Talkshow Host, Sexologist Dr. Emanuel Bronner 02-01-1908 03-07-1997 Soapmaker Vikki Carr 07-19-1941 ---- Singer Johnny Carson 10-23-1925 1-23-2005 Comedian, Host of The Tonight Show Cyd Charisse 3-8-1922 6-17-2008 Actor, Dancer Bryan Cranston 3-7-1956 ---- Actor, featured on Malcolm in the Middle Tony Danza 4-21-1951 ---- Actor, Television Host Sammy Davis, Jr. 12-8-1925 5-16-1990 Entertainer Cory Doctorow 7-17-1971 ---- Journalist, Author of Down and Out in the Magic Kingdom John Charles Dvorak c. 1952 ---- Technology Journalist Roy Wayne Ferris 1-25-1953 ---- Wrestler, AKA The Honky Tonk Man Shaenon Garrity 5-4-1978 ---- Web Cartoonist Billy Gibbons 12-16-1949 ---- Guitarist, Member of ZZ Top Kathy Griffin 11-4-1960 ---- Comedian, Host of My Life on the D-List Phil Hall c. 1953 ---- Writer, Contributer to Film Threat George Harrison 2-25-1943 11-29-2001 Musician, Member of The Beatles Goldie Hawn 11-21-1945 ---- Actor Doug Berry 11-21-1952 ---- Attorney Hugh Hefner 4-9-1926 ---- Founder of Playboy Kirby Hensley 7-23-1911 3-19-1999 Founder of The Universal Life Church Greg Hetson 6-29-1961 ---- Musician, Member of Bad Religion Abbie Hoffman 11-30-1936 4-12-1989 Activist, Author of Steal This Book Jesse James 4-19-1969 ---- Motorcycle Designer, Host of Monster Garage Carson Kressley 11-11-1969 ---- Fashion Expert, Appeared on Queer Eye Leo Laporte 11-29-1952 ---- Technology Journalist Denis Leary 8-18-1959 ---- Comedian John Lennon 10-9-1940 12-8-1980 Musician, Member of The Beatles Courtney Love 7-9-1964 ---- Musician, Kurt Cobain's Widdows Lydia Lunch 6-2-1959 ---- Punk, Spoken Word Confrontationalist Paul McCartney 6-19-1942 ---- Musician, Member of The Beatles John Cameron Mitchell 4-21-1963 ---- Writer, Actor, Director Alanis Morissette 6-1-1974 ---- Singer/Songwriter, Actress Steve Morrison 6-12-1959 ---- Radio Talkshow Host Jan Murray 10-4-1916 7-2-2006 Comedian Michael Newdow 6-24-1953 ---- Attacked Government Use of the Phrase "Under God" Paul Newman 1-26-1925 9-26-2008 Actor, Philanthropist Madalyn Murray O'Hair 4-13-1919 9-29-1995 Founder of American Atheists Anthony Perkins 4-4-1932 9-12-1992 Actor, Appeared in Psycho Jeff Probst 11-4-1962 ---- Producer, Host of Survivor Jerry Reinsdorf 2-25-1936 ---- Sports Franchise Owner Debbie Reynolds 4-1-1932 ---- Actress Nicole Richie 9-21-1981 ---- ACelebrity Heiress Rev. Al Ridenour 3-6-1961 ---- Journalist, Founder of the Cacophony Society Rosalind Russell 6-4-1907 11-27-1976 Actor John Scalzi 5-10-1969 ---- Science Fiction Author Tori Spelling 5-16-1973 ---- Actor Rev. Ivan Stang 8-21-1953 ---- Founder of The Church of the SubGenius Ringo Starr 7-7-1940 ---- Musician, Member of The Beatles Jimmy Stewart 5-20-1908 7-2-1997 Actor Sharon Stone 3-10-1958 ---- Actor Kristofer Straub 1-17-1979 ---- Web Cartoonist Barbra Streisand 4-24-1942 ---- Singer, Actress Hunter Thompson 7-18-1937 2-20-2005 Gonzo Journalist, Author Danny Wallace 11-16-1976 ---- Comedian John Waters 4-22-1946 ---- Filmmaker, Director of Hairspray Lawrence Welk 3-11-1903 5-17-1992 Band Leader, Host of The Lawrence Welk Show Mae West 8-17-1893 11-22-1980 Actor Robbie Williams 2-13-1974 ---- Musician, Member of Take That Doris Day 4-3-1924 ---- Singer, Actor This is just a selection of celebrities who are ordained as ministers through the Universal Life Church. If would like become ordained too, please visit our official Universal Life Church site. 0 - Done counting ministers items, now adding ministers. 

Scraper Object 
(
    [ministers:protected] => Array 
     (
     ) 

    [domain:protected] => http://www.universallifechurchministers.org 
) 

並與代碼未註釋:

2 - Done counting ministers items, now adding ministers. 

Scraper Object 
(
    [ministers:protected] => Array 
     (
      [0] => Array 
       (
        [img] => /images/rob-drydek-sm.jpg 
        [name] => Rob Dyrdek 
        [born] => 06-28-1974 
        [died] => ---- 
        [note] => Skateboarding Entrepreneur, Fantasy Factory on MTV 
       ) 

      [1] => Array 
       (
        [img] => /images/image1.jpg 
        [name] => Glenn Beck 
        [born] => 02-10-1964 
        [died] => ---- 
        [note] => Talk Radio Host 
       ) 

     ) 

    [domain:protected] => http://www.universallifechurchministers.org 
) 

這裏就是我指向的URL,只是爲了好措施

Famous Ministers

+0

請提供代碼重現錯誤的最小示例。 – FailedDev

+0

include('class/scraper.php'); print_r($ scrape = new Scraper('http://www.universallifechurchministers.org'));應該在任何PHP腳本中工作得很好,它只是一個帶有返回值的基本類,我的意思是...... – ehime

回答

0

答案是我是從的xpath缺少/格

$ ministerList = $ xpath->查詢(「// * [@ id中= 'site_content_sub']/DIV [2]/DIV「);

解決了這個問題。

--------------------------------------------- --------------