Mobile app version of vmapp.org
Login or Join
Hamaas447

: Possible to only load specific div of a website? I have this project I'm working on and id like to add a really small list of nearby places using Facebook's places in an iframe feature from

@Hamaas447

Posted in: #Html #Html5 #Iframe #Javascript

I have this project I'm working on and id like to add a really small list of nearby places using Facebook's 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.

I'd really rather figure out a way to just load only the section of content.

I went ahead and tried this approach in PHP. 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;
}
}
?>


But, I get a completely blank page.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamaas447

3 Comments

Sorted by latest first Latest Oldest Best

 

@Karen161

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.
php.net/manual/en/book.curl.php devzone.zend.com/article/1081

10% popularity Vote Up Vote Down


 

@Lengel546

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.

10% popularity Vote Up Vote Down


 

@Kristi941

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;
}
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme