Skip to content

Instantly share code, notes, and snippets.

@tuki0918
Last active August 29, 2015 14:03
Show Gist options
  • Save tuki0918/e6a285a31dd8c0c893c5 to your computer and use it in GitHub Desktop.
Save tuki0918/e6a285a31dd8c0c893c5 to your computer and use it in GitHub Desktop.
php: pixiv login get ranking html
<?php
/***********************************/
define('TEMP_DIR', sys_get_temp_dir());
/***********************************/
define('APP_NAME', 'pixiv');
define('APP_COOKIE_FILE', TEMP_DIR . '/cookie_' . APP_NAME . '.txt');
/***********************************/
define('PIXIV_LOGIN_URL', 'https://www.secure.pixiv.net/login.php');
define('PIXIV_BASE_URL', 'http://www.pixiv.net/');
define('PIXIV_RANKING_URL', PIXIV_BASE_URL . 'ranking.php');
/***********************************/
define('PIXIV_ID', 'USER_ID');
define('PIXIV_PW', 'PASSWORD');
/***********************************/
function login()
{
$request = array('pixiv_id' => PIXIV_ID, 'pass' => PIXIV_PW, 'mode' => 'login');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_URL, PIXIV_LOGIN_URL);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_COOKIEJAR, APP_COOKIE_FILE);
curl_exec($ch);
curl_close($ch);
}
function ranking()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, PIXIV_RANKING_URL);
curl_setopt($ch, CURLOPT_COOKIEFILE, APP_COOKIE_FILE);
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
login(); // 最初だけ
$html = ranking();
echo $html;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment