function getInsComData() { // 1.ログイン $data = array('mail_tel' => 'xxx@xxx.xxx', 'password' => 'xxxxxx'); $data = http_build_query($data); $context = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => implode("\r\n", array( 'Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen($data) ) ), 'content' => $data ))); $res = file_get_contents('https://secure.nicovideo.jp/secure/login?site=niconico', false, $context); // 2.ログインの結果からセッションを取得 $cookies = array(); foreach ($http_response_header as $v) { @list($key, $value) = explode(":", $v); if ($key == "Set-Cookie") $cookies[] = $value; } $sessionInfo = preg_replace("/(user_session=user_session_[a-z0-9_]+;)/","$1 Max-Age=-1",$cookies[2]); $header = array( 'Content-Type: application/x-www-form-urlencoded', 'Cookie: '.$sessionInfo ); $context = stream_context_create(array( 'http'=>array( 'method' => 'GET', 'header' => implode("\r\n",$header), 'content' => $data ))); // 3.エピソード一覧を取得 $xpath = $this->getXPath('http://seiga.nicovideo.jp/api/manga/episodes?id=xxxxx', $context); $episodeInfoList = $xpath->query("//episode"); foreach ($episodeInfoList as $wk) { // エピソード名とtheme_id $title = $wk->getElementsByTagName("title")->item(0)->nodeValue; $theme_id = $wk->getElementsByTagName("theme_id")->item(0)->nodeValue; // 4.threadIDを取得 $xpath = $this->getXPath('http://seiga.nicovideo.jp/api/theme/data?theme_id='.$theme_id, $context); $thread_id = $xpath->query("//thread")->item(0)->nodeValue; // 5.コメントを取得 $xpath = $this->getXPath('http://msg01.seiga.nicovideo.jp/api/thread?version=20090904&res_from=-1000&thread='.$thread_id, $context); $chats = $xpath->query("//chat"); foreach ($chats as $chat) { $date = date("Y-m-d H:i:s",(int)$chat->getAttribute("date")); $comment = $chat->nodeValue; printf("%s,%s,%s,%s", $title, $date, $comment); } } // 6.ログアウト file_get_contents('http://seiga.nicovideo.jp/logout', false, $context); }PHPのクソコード
フロー
1.ログインする。
2.1の結果からセッション情報を取り出す。
3.API使って漫画エピソード一覧を取得
4.API使って各エピソードのthreadID取り出す
5.API使ってコメントを抜き出す
6.ログアウト
途中にある$this->getXPathはfile_get_contentsしてxpathに変えるだけの関数だから、適当に補完しといて