Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have this project i'm working on and id like to add a really small list of nearby places using facebooks places in an iframe feature from touch.facebook.com I can easily just use touch.facebook.com/#places.php but then that loads the top bars.

Anyway, is there a way I could manipulate the URL so that it will only load the places content rather than having the top and bottom menu bars. After looking at the code it looks like there is a div id=content" I was thinking maybe there was a way to make the url so that it will only load that div? I also tried making a url that might just jump down to content using touch.facebook.com/#places.php#content but apparently with that way touch.facebook.com was built that doesn't work. But really i'd rather figure out a way to just load the content. Ay ideas? thanks!

edit again: I went ahead and tried this

I read the examples for file_get_contents and what's being here looks right, according to example 1

<?php
$page = file_get_contents('http://touch.facebook.com');
$doc = new DOMDocument();
$doc->loadHTML($page);
$divs = $doc->getElementsByTagName('div');
foreach($divs as $div) {
      if ($div->getAttribute('id') === 'content') {
         echo $div->nodeValue;
    }
}
?>

I get a completely blank page.

Sorry really new to php, trying to understand it. any suggestions?

share|improve this question
add comment

3 Answers

You won't be able to manipulate the URL to get only a portion of the page. So what you'll want to do is grab the page contents via the server-side language of your choice and then parse the HTML. From there you can grab the specific DIV you are looking for and then print that out to your screen. You could also use to remove unwanted content.

With PHP you could use file_get_contents() to read the file you want to parse and then use DOMDocument to parse it and grab the DIV you want.

Here's the basic idea. This is untested but should point you in the right direction:

$page = file_get_contents('http://touch.facebook.com');
$doc = new DOMDocument();
$doc->loadHTML($page);
$divs = $doc->getElementsByTagName('div');
foreach($divs as $div) {
    // Loop through the DIVs looking for one withan id of "content"
    // Then echo out its contents (pardon the pun)
    if ($div->getAttribute('id') === 'content') {
         echo $div->nodeValue;
    }
}
share|improve this answer
    
thank you! But, would you mind taking a quick look at my edit up top? –  brybam Sep 13 '10 at 3:18
    
Does the DIV you are looking for have the id of "content"? –  John Conde Sep 13 '10 at 3:58
    
yes <div id="content"> is what i'm trying to display –  brybam Sep 13 '10 at 13:11
    
Code amended to isolate the DIV with an ID if "content". FYI, the DOMDocument page I linked to shows you how to use it and get the content you are looking for. The examples in the comments are very helpful. –  John Conde Sep 13 '10 at 14:13
    
I went ahead and tried what you said, but it looks like there is an error with file_get_contents() is there another way it should be used? –  brybam Sep 13 '10 at 16:11
show 4 more comments

The page you are trying to access requires authentication. You were probably looking at the data that you wanted after you signed in. That is the reason why when you tried to scrape the page programmatically, it shows the login page's content.

Instead of using this scraping approach, you could check if the info you need can be extracted programmatically using Facebook's APIs

On a related note, you could use YQL to fetch a portion of any webpage on a public site. However in your case, it may not work as the page you are trying to access requires authentication.

share|improve this answer
    
I have seen it done before. The content div of the main page contains the login area, then after the user is authenticated i can have them redirected to the next page that contains another content div which is all i want to display. I really only have to worry about the authentication once, because i can keep them logged in. I really don't want to go into it programmatically since it's such a small thing im trying to do i figure it wouldnt be worth the time. and ive seen what im trying to figure out done before so i know it can be. –  brybam Sep 13 '10 at 13:14
add comment

Per other replies, I understand that you want to get some beyond authentication page.

Well, first you will need to log in, then access the page you need, and finally process the DOM iteration.

You have curl as an option to handle requests, thus log in. Also you can use curl to get pages content.

http://php.net/manual/en/book.curl.php

http://devzone.zend.com/article/1081

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.