Grab Alexa Top Sites by Category with PHP

Discussion in 'PHP' started by tonyrocks, Mar 2, 2010.

  1. #1
    I would like to get the list of top sites by category. Is there a way to do this using PHP/Curl? Or do I have to use their API? Seems like they are charging to use the cloud computing...I'm cheapo
     
    tonyrocks, Mar 2, 2010 IP
  2. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #2
    You can scrape it pretty easy but scraping is unreliable here's a working example
    
    $html=file_get_contents('http://www.alexa.com/topsites/category/Top/Sports');
    preg_match_all(
        '/<div class="desc-container">.*?<h2><a href=".*?">(.*?)<\/a><\/h2>/s',
        $html,
        $array, //array with sites
        PREG_SET_ORDER 
    );
    
    PHP:
    Then run a foreach or something on $array

    Cheers!
     
    Narrator, Mar 2, 2010 IP
  3. tonyrocks

    tonyrocks Active Member

    Messages:
    1,574
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    88
    #3
    thanks! This works great. I wish I knew how to "spider" each category. I guess that is a whole 'nother big thing.
     
    tonyrocks, Mar 3, 2010 IP