Skip to content

Instantly share code, notes, and snippets.

@Overv
Created March 30, 2013 14:07
Show Gist options
  • Save Overv/5276810 to your computer and use it in GitHub Desktop.
Save Overv/5276810 to your computer and use it in GitHub Desktop.
<?php
if (!isset($_GET['profile']) || !isset($_GET['page']) || !is_numeric($_GET['page']) || $_GET['page'] < 1) {
die("Specify a profile id and page as GET parameter.");
}
$page = intval($_GET['page']);
// Get profile
$profile = file_get_contents('http://steamcommunity.com/id/' . $_GET['profile']);
preg_match("/Profile_([0-9]+)/", $profile, $id); $id = $id[1];
preg_match("/\"total_count\":([0-9]+)/", $profile, $pages); $pages = $pages[1];
print("There's a total of " . $pages . " pages of comments. Page " . $page . " is shown here.<br />");
// Get first page
$ch = curl_init('http://steamcommunity.com/comment/Profile/render/' . $id . '/-1/');
curl_setopt($ch, CURLOPT_POST, 3);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'start=' . (($page - 1) * 6) . '&totalcount=' . $pages . '&count=6');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
curl_close($ch);
include('simple_html_dom.php');
$res = json_decode($res);
$res = $res->comments_html;
$html = str_get_html($res);
print("<ul>");
foreach ($html->find('.commentthread_comment') as $comment) {
$name = $comment->find('.commentthread_author_link', 0)->innertext;
$message = trim($comment->find('.commentthread_comment_text', 0)->innertext);
$avatar = $comment->find('img', 0)->src;
print('<li><img src="' . $avatar . '" style="position: relative; top: 10px;" /> <b>' . $name . '</b>: <i>' . $message . '</i></li>');
}
print("</ul>");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment