SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Clever Facebook Content Grab

    Hi,

    Does anyone know how Facebook does that clever content/image grab thing... When you're writing a message and paste in a link it goes off to the site mentioned and fetches back an array of images so you can choose which one you want to associate with the link. It also grabs the title of the page.

    I guess this can be done with some kind of Curl request to fetch the page contents!? Or maybe even file_get_contents() ? It's really clever though... Any tips would be greatly appreciated.

    Thanks,
    Tom
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  2. #2
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Posts
    1,295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know the one you mean. You'd have to use Ajax to do it without submitting the page for starters. Then I would go about it using curl to grab the page as you mentioned, then regex to extract the src from each img tag. Then you could return the title of the page, and all the img srcs you've collected. Probably you would want to screen for images only over a certain size.
    Actually it sounds like quite a fun little project - I might have a go later tonight. If I get something working then I'll post back here for you.
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


  3. #3
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers, how did it go?

    I'm working on it now... So far I've got the cUrl bit getting the page content ok, and managed to extract the content from the title tag using a function I've found on php.net, however I'm having problems getting the meta data out... It would be good to grab the description field...

    I haven't started on the image tags yet, but I guess I'll need to parse the document for image tags, then take out the src element... I'll also need to make sure they are all absolutely defined, using the baseUrl of the page I guess... Anyway I'd better get back to it. Please let me know how you get on.

    Oh and the Ajax bit is easy, jQuery ajax code does all the hard work for you
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  4. #4
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For anyone interested I managed to do it Using the same techniques as I described above. See it working on my new site... Still very much in Beta, but hopefully soon to be fully unleashed on the world

    naturalbornshopper.com

    The script seems to grab items very well from the major sites, but struggles on sites with lots of images as the getimagesize part of the script slows things down quite a bit... Works well on Argos.co.uk though Hehe I love this stuff!
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very interesting......sorry i can't find where abouts you have it working on your site...could you post an exact link?

  6. #6
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to sign up, go to your profile, then add an item to your page by entering the URL you want to grab an item from.

    I've also just created a little demonstration of the script on 18aproductions.
    Last edited by webchalkboard; Feb 2, 2008 at 17:11.
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping


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
  •