Created
September 10, 2009 18:31
-
-
Save sotarok/184718 to your computer and use it in GitHub Desktop.
つーかべつに汎用的なやつにしてもよかったんだけど.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PcjTwitterSearch.php | |
* search.twitter.com #pcj09 log | |
* | |
* @author sotarok | |
* @copyright 2009 sotarok | |
* @license The MIT License | |
*/ | |
require_once 'HTTP/Request2.php'; | |
$browser = new HTTP_Request2(); | |
$browser->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; ja-JP-mac; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'); | |
$url = "http://search.twitter.com/search.atom?q=%23pcj09"; | |
$entry_data = array(); | |
while(1) { | |
echo $url, "\n"; | |
$browser->setUrl($url); | |
$res = $browser->send(); | |
if ($res->getStatus() != 200) { | |
echo " ... error? server returned: ", $res->getStatus() , "\n"; | |
break; | |
} | |
$atom = simplexml_load_string($res->getBody()); | |
$atom->registerXPathNamespace('feed', 'http://www.w3.org/2005/Atom'); | |
foreach ($atom->entry as $entry) { | |
$entry_data[] = array( | |
strval($entry->link[0]->attributes()->href), | |
strval($entry->author->name), | |
strval($entry->updated), | |
strval($entry->content), | |
); | |
echo "\t", $entry->author->name, ": ", $entry->title, "\n"; | |
} | |
$url = $atom->xpath('//feed:link[@rel="next"]'); | |
if (empty($url)) { | |
echo "... maybe end.\n"; | |
break; | |
} | |
else { | |
$url = strval($url[0]->attributes()->href); | |
} | |
sleep(1); | |
} | |
file_put_contents("./pcj_twitter_log.serialized", serialize($entry_data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment