Created
January 30, 2020 15:33
-
-
Save ha1t/678597c3957c488234342a66094b92e0 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 | |
define('MIXI_EMAIL', '[email protected]'); | |
define('MIXI_PASSWORD', 'pass'); | |
/** | |
* mixiの日記削除スクリプト | |
* | |
* @author Kiryu Tsukimiya <[email protected]> | |
*/ | |
require_once('HTTP/Client.php'); | |
class DeleteMixiDiary | |
{ | |
/** | |
* mixiの基本URL | |
*/ | |
const BASE_URL = 'http://mixi.jp'; | |
/** | |
* HTTP_Clientオブジェクト | |
* | |
* @return HTTP_Client | |
*/ | |
private $_client; | |
/** | |
* 初期化処理 | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
// HTTP_Clientの初期化 | |
$this->_client = new HTTP_Client(); | |
} | |
/** | |
* mixiにログインする | |
* | |
* @param string $email | |
* @param string $password | |
* @return boolean | |
*/ | |
public function login($email = MIXI_EMAIL, $password = MIXI_PASSWORD) | |
{ | |
$params = array( | |
'next_url' => '/home.pl', | |
'email' => $email, | |
'password' => $password, | |
); | |
$this->_client->post(self::BASE_URL.'/login.pl', $params); | |
$response = $this->_client->currentResponse(); | |
// self::printDebug($response); | |
if (preg_match("'/check\.pl'", $response['body'])) { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* 日記ID一覧を取得する | |
* | |
* @return mixed | |
*/ | |
public function getDiaryIdList() | |
{ | |
$data = array(); | |
$this->_client->get(self::BASE_URL.'/list_diary.pl'); | |
$response = $this->_client->currentResponse(); | |
// self::printDebug($response['body']); | |
// HTMLからdiary_idを抜き取る | |
if (preg_match_all('/<a\shref="edit_diary.pl\?id=(\d+?)">/', $response['body'], $matches)) { | |
return $matches[1]; | |
} | |
return false; | |
} | |
/** | |
* | |
* @param $diary_id | |
* @return void | |
*/ | |
public function deleteDiary($diary_id) | |
{ | |
// 確認画面の表示 | |
$this->_client->post(self::BASE_URL.'/delete_diary.pl?id='.$diary_id, array()); | |
$response = $this->_client->currentResponse(); | |
// post_keyの取得 | |
if (preg_match('/<input\stype=hidden\sname=post_key\svalue="(.*?)">/', $response['body'], $matches)) { | |
$post_key = $matches[1]; | |
} | |
// 削除 | |
$params = array( | |
'submit' => 'confirm', | |
'post_key' => $post_key, | |
); | |
$this->_client->post(self::BASE_URL.'/delete_diary.pl?id='.$diary_id, $params); | |
$response = $this->_client->currentResponse(); | |
echo sprintf("deleted: diary_id = %d<br />\n", $diary_id); | |
} | |
/** | |
* デバッグプリント | |
* | |
* @param mixed $data | |
* @return void | |
*/ | |
static public function printDebug($data) | |
{ | |
mb_convert_variables('SJIS-win', 'EUC-jp', $data); | |
print_r($data); | |
} | |
} | |
/** | |
* Application Entry Point | |
*/ | |
$obj = new DeleteMixiDiary(); | |
$obj->login(); | |
while ($diary_ids = $obj->getDiaryIdList()) { | |
foreach($diary_ids as $diary_id) { | |
sleep(1); | |
$obj->deleteDiary($diary_id); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment