SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Quick RegExp

Hybrid View

  1. #1
    SitePoint Enthusiast ivanfx's Avatar
    Join Date
    May 2007
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Quick RegExp

    Hello

    I've been trying for over a month now and I can't get it to work

    I'm trying to make a little widget for my site that parses Google results
    so that my visitors don't have to go away from the site

    This is what I've done so far:

    Code:
    // open the site
    $handle=fopen("full url for searching", 'r');
    
    // place it in a string
    while (!feof($handle))
    {
    $content .= fgets($handle, 4096);
    }
    
    // strip out the divs with data
    preg_match('/<div class=\"g\">.*<\/div>/', $content, $result);
    
    // output the results
    foreach($result as $div)
    {
    echo $div;
    }
    After that I try and parse each div so I would get the URL, title and
    description, but it doesn't work..

    I've tried &output=xml - but Google banned that approach.

    Can anybody give a hand?
    What I would like to get as the result is:

    TITLE
    DESCRIPTION
    URL

    Thanks in advance!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    http://www.google.com/accounts/TOS?loc=US
    Quote Originally Posted by Google Terms of Service
    5.3 You agree not to access (or attempt to access) any of the Services by any means other than through the interface that is provided by Google, unless you have been specifically allowed to do so in a separate agreement with Google. You specifically agree not to access (or attempt to access) any of the Services through any automated means (including use of scripts or web crawlers) and shall ensure that you comply with the instructions set out in any robots.txt file present on the Services.

  3. #3
    SitePoint Enthusiast ivanfx's Avatar
    Join Date
    May 2007
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I know that, but they won't even notice me.
    I have 10 users a day

  4. #4
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ivanfx View Post
    Yeah, I know that, but they won't even notice me.
    I have 10 users a day
    Pretty much like my blog

  5. #5
    SitePoint Enthusiast ivanfx's Avatar
    Join Date
    May 2007
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK,
    can anybody help me extract a div from a page?

    It looks like this:

    <div id="idname"> ... </div>

    Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •