Help in Preg Match pattern in a google search result using curl library

Discussion in 'PHP' started by jigen7, Sep 18, 2007.

  1. #1
    i need to print the top 5 url search result from a google result so by using curl library i can save the entire page to a variable so that i can return it the one in green fonts are the url i need to return/store to a variable(array)?? can anyone help me here thx

    function curl_google($keyword){

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/search?hl=en&num=5&q='.urlencode($keyword).'&btnG=Google+Search&meta=');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FILETIME, true);
    $data = curl_exec($ch);
    curl_close($ch);

    //preg_match code help
    //return urls
    }
     
    jigen7, Sep 18, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    You may want to look into using a google custom search api instead. It will return an xml doxument of the result set, which would be far easier than scraping the results with curl.

    Try this out, if you're interested:
    http://www.google.com/coop/cse/

    Also, I wrote a really simple script for it a while back that should do pretty much whatever you need to get started with it.
    http://www.ecommerce-blog.org/archives/adding-google-business-search-to-your-ecommerce-website/

    Try this to get you started with the curl script:
    http://www.vxml.org/frame.jsp?page=t_18.htm
     
    jestep, Sep 18, 2007 IP
  3. jigen7

    jigen7 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well yes but my supervisor told me i need to use curl so that the process time is faster than using any api and the way i think of it i jsut need to save the page into a variable the use !feof??? then preg mtach pattern to get the urls out of it
     
    jigen7, Sep 18, 2007 IP