$breakFlag = 1; ob_start(); //打开输出控制缓冲 ob_end_flush(); //输出缓冲区内容并关闭缓冲 ob_implicit_flush(1); //立即输出 foreach ($content[0]->find('a') as $element) { $hrefStr = $companyUrl . $element->href; $productName = strtolower($element->plaintext); echo $hrefStr . '--' . $productName . '<br/>'; //abs,pla直径信息 $diameterInformation = array(); //调用产品信息类 $productDetails = new ProductDetails(); $productHtml = $productDetails->getHtml($hrefStr); $productDetailFromJs = new ProductDetailsFromJS(); $productInfo = array(); if (strcasecmp($productName, 'abs') == 0) { $productInfo = $productDetailFromJs->getAbsProductInfo($productHtml, $productName); $diameterInformation = $productDetails->getDiameters($productHtml); } else { if (strcasecmp($productName, 'pla') == 0) { $productInfo = $productDetailFromJs->getPlaProductInfo($productHtml, $productName); $diameterInformation = $productDetails->getPlaDiameters($productHtml); } } //图片 if (strcasecmp($productName, 'pla') == 0) { $imageUrl = $productDetails->getPlaImage($productHtml); } else {
case '$': $priceUnit = 'USD'; break; case '¥': $priceUnit = 'RMB'; break; case '£': $priceUnit = 'GBP'; break; default: $priceUnit = 'USD'; break; } //调用产品信息类 $productDetail = new ProductDetails(); $productHtml = $productDetail->getHtml($url); // $productDetailInformation = $productDetail->getProductDetails($url); echo 'FilaMent List: Index ----' . $index . '<br/>'; echo 'Picture link : ' . $imageUrl . '<br/>' . 'Name : ' . $materialType . '<br/>' . 'Link : ' . $startUrl . '<br/>' . 'Manufacture : ' . $producer . '<br/>' . 'Price : ' . $price; echo '<br/>---------------------------------------------------------------------<br/>'; $diameterIndex = $productDetail->setDiameterIndex($url); $diameterInfo = $productDetail->getDiameters($productHtml, $diameterIndex); $weightInfo = $productDetail->getWeight($productHtml); $colorInfo = $productDetail->getColor($productHtml); $description = $productDetail->getFeatures($productHtml); $diameter = $diameterInfo['diameter']; $diameterUnit = $diameterInfo['diameterUnit']; $weight = $weightInfo['weight']; $weightUnit = $weightInfo['weightUnit']; $packForm = $weightInfo['packForm']; $weightInKg = $weightInfo['weightInKg'];
<?php include 'simple_html_dom.php'; $url = 'http://www.amazon.com/s/ref=sr_pg_200/186-9579278-0825442?rh=n%3A16310091%2Cn%3A!16310161%2Cn%3A6066126011%2Cn%3A6066128011&page=200&ie=UTF8&qid=1460039178&spIA=B01A524ZKI,B019PGZQO4'; // $url = 'http://store.makerbot.com/dissolvable-filament.html'; // $url = "http://store.makerbot.com/filament/flexible"; //$url = "http://store.makerbot.com/filament/abs"; $product = new ProductDetails(); $html = $product->getHtml($url); // $product->getList($html); $result = $html->find('#result_3201', 0); echo $result; // $product->getPlaImage($html); // $product->getWeight($html); // $product->getFeatures($html,"abs"); // $product->getPlaColor($html); //$product->getDiameters($html); // $product->getPrice($html); // echo $product->delete_special_mark($str); class ProductDetails { function getHtml($url) { $html = file_get_html($url); return $html; } function getList($html) { $ulsdiv = $html->find('.s-result-item'); // echo $ulsdiv[5]; // $lis = $ulsdiv->find('li');