Getting ‘Techmeme’ Top News

One of the questions from quora is like this “Techmeme: Can the “top news” rss feed still be accessed or brought back?

I went to that question after searching a solution for “How to get techmeme top news”.  Why, techmeme doesn’t have rss for top news? No, it probably had before, but currently they don’t.  They have rss for the tech news, which is kind of, mix of recent news, top news etc.

Techmeme is one of those websites I visit everyday, doesn’t matter how busy I’m. It’s one of my favourite sites without any doubt. As I read it everyday, I wanted to make it easier for myself to read and share, and to do that I needed RSS for top news.

Since the time I realized there was no way to get rss for techmeme top news, I started looking for alternatives. And yes, finally I have found a way to get techmeme TOP news using simple “Simple html dom”. Techeme has mini page and one of the sections contains top news. That’s it! All we need is to dig for correct information. Have a look at the little hack…

< ?php
include_once('../simple_html_dom.php');
// Create DOM from URL or file
$html = file_get_html('http://techmeme.com/mini');
$list = array();
$i = 0;
foreach ($html->find('div.mini_item') as $element) {
    /*
     * first 14 news are top news
     */
    if($i< =13) {
        if(isset($element->find('a', 0)->class) && $element->find('a', 0)->class=='mini_head') {
            if($element->previousSibling(0)->innertext == 'RELATED:') {
                $output['List'][$i]['from']   = $element->childNodes(0)->innertext.' (RELATED)';
            }else {
                $output['List'][$i]['from']   = $element->childNodes(0)->innertext;
            }
            $output['List'][$i]['title']   = $element->find('a', 0)->innertext;
            $output['List'][$i]['link']  = $element->find('a', 0)->href;
           $i++;
        }
        else if (isset($element->find('div', 0)->class) || isset($element->find('a div', 1)->class)) {
            if($element->previousSibling(0)->innertext == 'RELATED:') {
                $output['List'][$i]['from']   = $element->childNodes(0)->innertext.' (RELATED)';
            }else {
                $output['List'][$i]['from']   = $element->childNodes(0)->innertext;
            }
            $output['List'][$i]['title']   = $element->find('div a', 0)->innertext;
            $output['List'][$i]['link']  = $element->find('div a', 0)->href;
            $i++;
        }
   }
}
if (empty($output['List'])) {
    $output['List']['msg'] = 'No Result Found';
}
 
print(json_encode($output));
exit();

You can get full source code from this link
Let me know if you have any questions. Have better idea to improve it?

Now I’m going to take it a little further. What’s that? Stay tune…

This entry was posted in PHP, Technology, Web and tagged , , , . Bookmark the permalink.