SimpleXMLElementでTwitterのスクレイピング(だめな例)

PHP+SimpleXMLElementでTwitterスクレイピング - GRANADA Hatena @ sotarok
http://d.hatena.ne.jp/sotarok/20080121/1200889073
ZFとtidyのだめな例だとこうかな?(というか以前に作った中途半端なScrapeクラスの場合)

<?php
//@see http://diggin.googlecode.com/svn/trunk/library/Diggin/Scraper/Simple.php
require_once '/workspace/ax/library/Diggin/Scraper/Simple.php';

$scraper = new Diggin_Scraper_Simple("http://twitter.com/sasezaki/with_friends");
$content = $scraper->scrape('//tr[@class="hentry"]//td[@class="content"]');

$results = array();
$count = count($content);
for ($i = 0; $i < $count; $i++) {
    //$result[$i]['id']        = substr((string)$val['id'], 7);
    $results[$i]['id']        =  substr((string)$content[$i]->span[1]->span[0]['id'], 15);
    $results[$i]['name']      = (string)$content[$i]->strong->a;
    $results[$i]['body']      = trim(strip_tags($content[$i]->span[0]->asXML()));
    $results[$i]['permalink'] = (string)$content[$i]->span[1]->a[0]['href'];
    $results[$i]['date']      = (string)$content[$i]->span[1]->a[0]->abbr['title'];
    //'application'  => (isset($content[0]->span[1]->a[1])) ? (string)$content[0]->span[1]->a[1] : null ,
    //'replies'   => (isset($content[0]->span[1]->a[2])) ? substr((string)$content[0]->span[1]->a[2], 12)  : null,
}

var_dump($results);

まあ、tidyレンサバでつかえないだろうと言う話だけど。。。。

個人的には、php5ってことならテストアダブタやれるからpearのHTTP_RequestじゃなくてZend_Http_Client使うclassがいい(笑)

phpにもWeb::Scraperみたいな奴はほしいですねえ

あ、けど、Web::Scraperのもとになったrubyのライブラリってtidy使ってるんだっけかな。



__constrActはたぶん釣り。。。