?
Solved

Retrieving DIV content by ID

Posted on 2009-04-13
4
Medium Priority
?
765 Views
Last Modified: 2013-12-12
Hi guys is there a way to retrieve the content of a certain DIV from a website? I want that when a form is filled in my form my PHP script retrieve the contents of a DIV with a certain ID from another site, is that possible, and if it is; How would I go about it?
0
Comment
Question by:doRodrigo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:dan_neal
ID: 24134467
Depending on the content of the DIV you would want to call either the innerHTML or innerText for the div.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24134632
>>is there a way to retrieve the content of a certain DIV from a website?

from a different domain name? I guess you will get a Permission Denied error if you try to retrieve other site's content using javascript XMLHTTP request, but certainly I'm not sure other methods available in php whether can accomplish this or not.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24135797
Scrape is the technical terminology here
Scrape DIV in this case

Disclaimer: Don't scrape if you don't have permission
</php
 
$url = "http://www.theremotesitehere.com/page.html";
 
$raw = file_get_contents($url);
 
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
 
$content = str_replace($newlines, "", html_entity_decode($raw));
 
$start = strpos($content,'<div class="unique name here"');
 
$end = strpos($content,'</div>',$start) + 6; // add 6 becuase of </div> is 6 chars long
 
$div = substr($content,$start,$end-$start);
 
// you can go further and extract inside your div as you wish now
// by accessing $div
 
?>

Open in new window

0
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 2000 total points
ID: 24135880
oops <?php

;)
<?php
 
$url = "http://www.theremotesitehere.com/page.html";
 
$raw = file_get_contents($url);
 
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
 
$content = str_replace($newlines, "", html_entity_decode($raw));
 
$start = strpos($content,'<div class="unique name here"');
 
$end = strpos($content,'</div>',$start) + 6; // add 6 becuase of </div> is 6 chars long
 
$div = substr($content,$start,$end-$start);
 
// you can go further and extract inside your div as you wish now
// by accessing $div
 
?>

Open in new window

0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question