<p>What is the most efficient way to determine how many comments a particular blog post has? We want to store the data for a new web app. We have a list of permalink URl's as well as the RSS feeds. </p>

[{'answer_id': 47871, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 2, 'selected': False, 'text': '<p>If the blog is controlled by you, a "Select count(commentid) FROM comments WHERE postID = 2" will possibly the best thing. If you only have the URL but still it\'s your blog/db, you need to create a subquery "WHERE postID = (SELECT whatever FROM posts WHERE permalink = url)" or whatever your way to join the comments to the posts from a URL.</p>\n\n<p>If it\'s a remote blog, you have the problem that each blog has different HTML. Essentially, you\'re going to need to build a parser that parses the HTML and looks for repeating elements like "div class=comment". But that will be mostly a manual labour for each different blogs.</p>\n\n<p>Some blogs may have better ways like a comment count somewhere in the HTML or some interface, but i\'m not aware of any standardized way.</p>\n\n<p>EDIT: If you got a Comment-RSS feed, you <em>may</em> have luck using a mechanism that counts XML nodes, like XPath\'s <a href="http://msdn.microsoft.com/en-us/library/ms256103.aspx" rel="nofollow noreferrer">Count</a>.</p>\n'}, {'answer_id': 48050, 'author': 'Matt Sheppard', 'author_id': 797, 'author_profile': 'https://Stackoverflow.com/users/797', 'pm_score': 3, 'selected': True, 'text': '<p>If I understand correctly, you want a heuristic to estimate the number of comments in an HTML page which is known to be a blog post, yes?</p>\n\n<p>Very often, a specific blog will have some features which make it easy to work out. If you look at mine over at <a href="http://kstruct.com/" rel="nofollow noreferrer">http://kstruct.com/</a> you\'ll see that all the pages with comments say \'X Responses\', so if you were able to do some work on a per blog basis, it\'s probably not really difficult.</p>\n\n<p>If you needed something generic, I guess there are a few common features that comments have that you might be able to detect. For one, any links in them are quite likely to have rel="nofollow" attributes, so seeing that within a block might imply that it\'s a comment. </p>\n\n<p>The main interesting thing to look for would be changes in the structure of posts for m the same site. For example, there\'s also a very good chance that each comment will have its own anchor so people can link directly to it, so you could look at the differing numbers of &lt;a name="XXX"&gt; tags in a given page on the same site to get an idea of the relative numbers of comments.</p>\n\n<p>As Michael Stum pointed out, if the pages have a Comment-RSS feed, your life is made a lot easier because you can get the comment data in a structured format.</p>\n\n<p>All in all, though, I think it\'s going to be quite a challenging problem to solve in general.</p>\n'}, {'answer_id': 48069, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Blogs almost always have an RSS feed for comments. If you have that, then you can determine the exact number of comments, since the feeds 99% of the time follow a standard. Even if the blog is your own, if you are already generating an RSS feed, then don't bother making a call to your DB. You already did that to generate the feed, so it makes sense that you would just traverse the XML nodes. That way you don't have additional overhead (depending on how often you want to get this information).</p>\n"}]
['https://Stackoverflow.com/questions/47869', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/281/']