SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    how to exctract a page title from a given URL

    Hello everyone,
    I found a solution to exctract a page title from a URL:
    Code:
    $x = file_get_contents($URL);
    preg_match("/<title>(.+?)<\/title>/", $x, $match);
    However, when trying on facebook it didnt work, it returned "Incompatible Browser | Facebook", is there another way to get this work on every site including FB?

    thanks,
    ulthane.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    see if you get any joy with http://php.net/manual/en/function.get-meta-tags.php instead.

  3. #3
    SitePoint Zealot Sogo7's Avatar
    Join Date
    May 2011
    Posts
    129
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Facebook is not your typical website and it will take a bit more than file_get_contents to extract any data from a page. Both cookies and an AJAX call are involved with opening a page so it's probably a job for cURL. Failing that Facebook does have a developers API and you may be able to get the information you want through that a whole lot easier.
    Lovelogic.net Personal Projects Pit - Spammers welcome

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you both for the answers
    but i dont think meta tags is what i need, because meta tag is not always the same as a page tite... (facebook is an example, each page has different titlte but all got the same meta description...)

    What developer API do they have that will enable me to get a page title from them?

  5. #5
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    go into page source and You will find title tag and text between the tag will be the title of that page

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    What data specifically are you trying to get? If it's something that can be retrieved using the API's, use that. If it isnt, you're violating Facebook's Terms of Service and we cannot support you in this script. Facebook clearly states that you may not '...access Facebook...using automated means (such as harvesting bots, robots, spiders, or scrapers) without our permission.'
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I tried searching their API and i couldn't find it, but i dont know if i search the right way...
    I'm simply trying to retrive a specific page title from their site to put in a link tag (like this: <a href="www.some-facebook.page.com">the page title</a>)
    Each page of facebook has a title given by the creator of the page, which is the best way to describe the link i wanna put...

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Issue solved...all i need was adding this line...
    Code:
    ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11');

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    It's still a violation of Facebook's ToS.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes you're right, I don't really get the point but anyway, i've changed it so every url that includes fb in it will be named "facebook"
    Anyway all pages that do not have public rights are named like this.

  11. #11
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    @ulthane

    Hi, have you thought about trying to contact Facebook for permission? If what you are doing is actually quite benign then they may allow it. To date I have asked for such permission from Coca-Cola, Nautilus Equipment, and Google and in each case they granted me limited rights but enough for what I needed to do. This way you don't have to worry about it, especially if someone challenges you.

    Steve
    ictus==""


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
  •