-2
私は、PHPで(一瞬でそれを得るために必要な)APIを使用せずにフォロワーのTwitterの数を取得したいと思っていました。Twitterのフォロワー数をAPIなしでPHPで取得する
でも、他のページのフォロワーの数が欲しかったです。
私は、PHPで(一瞬でそれを得るために必要な)APIを使用せずにフォロワーのTwitterの数を取得したいと思っていました。Twitterのフォロワー数をAPIなしでPHPで取得する
でも、他のページのフォロワーの数が欲しかったです。
は、私はちょうどこの小さなコードを開発したANそれは動作しますので、あなただけのTwitterページのフォロワーの数を取得する必要がある場合は、それを使用する:
function getTwitterFollowers($twitter = 'google', $lang = 'fr') {
// get page
$ch = file_get_contents('https://twitter.com/'. $twitter .'?lang='. $lang);
$doc = new DOMDocument();
$doc->loadHTML($ch);
$finder = new DomXPath($doc);
$classname="ProfileNav-stat";
$nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]");
// translate followers in each lang to replace it
$langs = array(
'fr' => 'Abonnés',
'en' => 'Followers',
);
return str_replace($langs[$lang] . $langs[$lang], '', str_replace(' ', '', preg_replace('/\R/', '', $nodes[2]->textContent)));
}
echo getTwitterFollowers('google', 'fr');
好奇心は、あなたが質問をし、答えと同じ時間を追加しました – Akintunde007
ちょうどコードを共有したいと思っています:)これをGithubや他の場所に置いてはいけません。 –
改良が可能なのでgithubの方が良いでしょう.bug fixesなど – Akintunde007