Viewing source code files from the server
which support rendering for: book_details
book_details.html :
entry point, with only SSI (Server Side Include) statements
<!--#include virtual="/inc/head.ssi" --> <!--#include virtual="book_details.php" --> <!--#set var="src_code" value="?src=book_details" --> <!--#include virtual="bottom_src.ssi" -->
book_details.php :
the PHP server side code does the data doing accross the internet
<?php error_reporting(E_ALL); ini_set('display_errors', 'On'); class product { public $mURL; public $details = array('ISBN10' => "1234", 'ISBN13' => "", 'Weight' => "", 'Dimensions' => "", 'CurPrice' => ""); function product($url) { $this->mURL = $url; // $contents = file_get_contents($url); // the use of cURL functions (for security) but I don't have them installed' // $contents = file_get_contents("http://192.168.1.40/TestPHP/fetch_html.php?url=$url"); // $contents = file_get_contents("http://google.com"); // NOTICE: Amazon seems to now block the action of getting page content as above (non browser-Javascript based) // therefore the following temporary work-around, for demostration purposes ... $contents = file_get_contents('cached_book_page.txt'); $contents= preg_replace('/[[:^print:]]/', '', $contents); // remove all non-printable characters //print $contents; //print "passed: " . $this->mURL; // preg_match('/class="priceLarge">(.*)</', $contents, $match); preg_match('/class=".* header-price">(.*?)</', $contents, $match); $this->details['CurPrice'] = trim($match[1]); // narrow the string down to the 'Product Details' section preg_match('/Product Details(.*)/' , $contents, $match); $stpos = stripos($contents, "<h2>Product Details<"); $endpos = strpos($contents, "<table", $stpos+1); $prodetails = substr($contents, $stpos, $endpos-$stpos); //print_r ($match); //print "st: $stpos end: $endpos <br/>" . $prodetails; preg_match('/ISBN-10:.*?>(.*?)</', $prodetails, $match); $this->details['ISBN10'] = $match[1]; preg_match('/ISBN-13:.*?>(.*?)</', $prodetails, $match); $this->details['ISBN13'] = $match[1]; preg_match('/Weight:[^>]*>([^<\(]*)/', $prodetails, $match); $this->details['Weight'] = $match[1]; preg_match('/Dimensions:[^>]*>([^<\(]*)/', $prodetails, $match); $this->details['Dimensions'] = $match[1]; } } //$bookURL = "http://www.amazon.com/Biology-MasteringBiology-8th-Neil-Campbell/dp/0321543254/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1233281929&sr=8-1"; $bookURL = "http://www.amazon.com/Biology-MasteringBiology-8th-Neil-Campbell/dp/0321543254"; print "<h1><center>Book Details</center></h1>"; print "This page : <small><font color='blue'>$bookURL</font></small><br/>"; print "was scraped for book details inbedded within it... Results:<br/>"; $book = new product($bookURL); //echo "<p> mURL: " . $book->mURL . "<br/>"; //var_dump ($book->details); print "<p>ISBN10: " . $book->details['ISBN10'] . "</p>"; print "<p>ISBN13: " . $book->details['ISBN13'] . "</p>"; print "<p>Weight: {$book->details['Weight']} </p>"; print "<p>Dimensions: {$book->details['Dimensions']} </p>"; echo "<p>CurPrice: {$book->details['CurPrice']} </p>"; ?>
|
Site Home
|
msg: Site Administrator
|
RonMiller
©1999-2021
From:
Include an email addr if a response is desired.