Created
April 20, 2012 09:54
-
-
Save ha1t/2427428 to your computer and use it in GitHub Desktop.
PHPプロ!のnewsが何回他のニュースサイトから引用しているかチェックするスクリプトとか書いたなー
This file contains hidden or 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 | |
/** | |
* PHPプロ!のnewsで何回他のニュースサイトから | |
* 引用しているかチェックするスクリプト | |
* | |
*/ | |
require_once 'HTTP/Client.php'; | |
$g_target_url = 'http://www.phppro.jp/news/'; | |
$g_start = 215; | |
function getNews($url) | |
{ | |
$matches = array(); | |
$client = new HTTP_Client(); | |
$client->get($url); | |
$response = $client->currentResponse(); | |
$pattern = '/id=\"news-\">(.*?)<!-- <\/dl> -->/s'; | |
preg_match($pattern, $response['body'], $matches); | |
return $matches[1]; | |
} | |
$quoted_count = array(); | |
$news_site_words = array('gigazine', 'phpspot', 'hotphpper'); | |
for ($i = 1; $i <= $g_start; $i++) { | |
print("get {$g_target_url}{$i}\n"); | |
$body = getNews($g_target_url . $i); | |
sleep(1); //wait 1 sec | |
foreach ($news_site_words as $keyword) { | |
if (stripos($body, $keyword) !== false) { | |
$quoted_count[$i] = $keyword; | |
} | |
} | |
} | |
$php = "<?php " . var_export($quoted_count, true) . "; ?>"; | |
file_put_contents('quoted_count.php', $php); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment