Reputation: 25
I'm currently designing a website for a company that uses an external site to display information about its clients. Currently, their old website just puts a link to the external profile of each client. however with this rebuild, I wondered if there was any way to load a specific portion of the external site onto their new page.
I've done my research, and I've found it's possible using jQuery and AJAX (with a bit of a mod) but all the tutorials relate to a div tag being lifted from the external site then loaded into the new div tag on the page.
Here's my problem: after reviewing the source code of the external source, the line of HTML I want isn't contained in a named DIV (other than the master wrap and I can't load that!)
The tag I need is literally: <p class="currentAppearance"> data </p>
It's on a different line for each profile so I can't just load line 200 and hope for the best.
Does anyone have any solution (preferably using php) that searches for that tag on an external page and then loads the specific tag into a div?
I hope I've been clear I am quite new to all this back end stuff!
Upvotes: 0
Views: 1388
Reputation: 14691
First I would use to grab the content from the webpage: http://www.php.net/manual/en/curl.examples-basic.php
$url = 'http://www.some-domain.com/some-page';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$htmlContent = curl_exec($curl);
curl_close($curl);
Then using DomDocument
(http://ca3.php.net/manual/en/book.dom.php) you'll be able to access the right div based on its ID for instance.
$doc = new DOMDocument();
$doc->loadHTML($htmlContent);
foreach ($pElements as $pEl) {
if ($pEl->getAttribute('class') == 'currentAppearance') {
$pContent = $pEl->nodeValue;
}
}
$pContent
is now set with the content of the paragraph with class currentAppearance
Upvotes: 2