|
|
|
สอบถามการดึงข้อมูลสินค้าของ Amazon เช่น ชื่อสินค้า รูปภาพ โดยใช้ Xpath เป็นตัวดึงพอจะมีวิธีไหมครับ ช่วยแนะนำด้วยครับ |
|
|
|
|
|
|
|
ผมเคยเขียนไว้ครับ เดียวพรุ่งนี้นำมาแจกครับ
|
|
|
|
|
Date :
2013-01-22 21:01:28 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เคยเขียนไว้นานแล้ว
Code (PHP)
function makeAWSUrl($parameters, $associate_tag, $access_key, $secret_key, $aws_version = '2009-10-01') {
$host = 'ecs.amazonaws.com';
$path = '/onca/xml';
$query = array(
'Service' => 'AWSECommerceService',
'AWSAccessKeyId' => $access_key,
'AssociateTag' => $associate_tag,
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'Version' => $aws_version,
);
if (is_array($parameters)) {
$query = array_merge($query, $parameters);
}
ksort($query);
$temp = array();
foreach ($query as $k => $v) {
$temp[] = str_replace('%7E', '~', rawurlencode($k)) . '=' . str_replace('%7E', '~', rawurlencode($v));
}
$signable = implode('&', $temp);
$stringToSign = "GET\n$host\n$path\n$signable";
$hex_str = hash_hmac('sha256', $stringToSign, $secret_key);
$raw = '';
for ($i = 0; $i < strlen($hex_str); $i += 2) {
$raw .= chr(hexdec(substr($hex_str, $i, 2)));
}
$query['Signature'] = base64_encode($raw);
ksort($query);
$temp = array();
foreach ($query as $k => $v) {
$temp[] = rawurlencode($k) . '=' . rawurlencode($v);
}
$final = implode('&', $temp);
echo 'http://' . $host . $path . '?' . $final;
echo "<br><br><br>";
return 'http://' . $host . $path . '?' . $final;
}
//rg = ResponseGroup.new( 'Medium', 'Offers', 'Reviews' )
$url = makeAWSUrl(array('Operation' => 'ItemLookup', 'ResponseGroup' => 'Medium', 'ItemId' => $ItemId), $AssociateTag, $public_key, $private_key);
$xml = simplexml_load_file ($url);
print_r($xml);
/*
$ii = 0;
foreach($xml->Items as $results) {
$totalresults = $results->TotalResults;
$totalpages = $results->TotalPages;
echo "<p>Total Results is: $totalresults<br />Total Pages is: $totalpages</p>";
}
echo "<p>$a_nav</p>";
*/
$iii = 0;
foreach($xml->Items->Item as $item) {
//print_r($item)."<br><br>";
$ASIN = $item->ASIN;
$Name = $item->ItemAttributes->Title;
$Brand = $item->ItemAttributes->Brand;
$Model = $item->ItemAttributes->Model;
$ListPrice = $item->ItemAttributes->ListPrice->FormattedPrice;
$LowestNewPrice = $item->OfferSummary->LowestNewPrice->FormattedPrice;
$ProductGroup = $item->ItemAttributes->ProductGroup;
$ProductTypeName = $item->ItemAttributes->ProductTypeName;
$Publisher = $item->ItemAttributes->Publisher;
$Studio = $item->ItemAttributes->Studio;
$SalesRank = $item->SalesRank;
$SmallImage = $item->SmallImage->URL;
$MediumImage = $item->MediumImage->URL;
$LargeImage = $item->LargeImage->URL;
//$ImageSets1 = $item->ImageSets->ImageSet ->LargeImage->URL;
$ImgReview = "";
foreach($item->ImageSets->ImageSet as $results) {
$ImgReview = $ImgReview.$results->LargeImage->URL."<br>";
}
$Feature = "<div class=\"content\">\r\n";
$Feature = $Feature."<ul style=\"LIST-STYLE-TYPE: disc; MARGIN-LEFT: 25px\">\r\n";
foreach($item->ItemAttributes->Feature as $results) {
$Feature = $Feature."<li>".$results."</li>\r\n";
}
$Feature = $Feature."</ul></div>";
//echo "Feature =$Feature <br />";
//$Description = $item->EditorialReviews->EditorialReview->Content;
//$Description2 = $item->EditorialReviews->EditorialReview->Content[1];
foreach($item->EditorialReviews->EditorialReview as $results) {
$Description[] =$results->Content;
//echo "<font color=red>Description</font> = ".$Description;
}
$BandMaterialType = $item->ItemAttributes->BandMaterialType;
$BezelMaterialType = $item->ItemAttributes->BezelMaterialType;
/*
echo "<br><br><br><hr>";
echo "ASIN = $ASIN<br />";
echo "Name = $Name <br />";
echo "Brand = $Brand<br />";
echo "Model = $Model<br />";
echo "ListPrice = $ListPrice <br />";
echo "LowestNewPrice = $LowestNewPrice <br />";
echo "ProductGroup = $ProductGroup <br />";
echo "ProductTypeName = $ProductTypeName <br />";
echo "Publisher = $Publisher <br />";
echo "Studio = $Studio <br />";
echo "SalesRank = $SalesRank <br />";
echo "SmallImage = $SmallImage <br />";
echo "MediumImage = $MediumImage <br />";
echo "LargeImage = $LargeImage <br />";
echo "Feature = $Feature <br />";
echo "BandMaterialType = $BandMaterialType <br />";
echo "BezelMaterialType = $BezelMaterialType <br />";
echo "ImgReview = $ImgReview <br />";
*/
|
|
|
|
|
Date :
2013-01-23 09:12:00 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ItemId แค่นั้นครับเป็น ASIN ID
|
|
|
|
|
Date :
2013-01-23 10:39:14 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ประมาณนั้นครับ
|
|
|
|
|
Date :
2013-01-23 10:54:54 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8;" />
</head>
<body>
<form action="Amazon xpath.php" method="post" name="info product" id="info product">
<td width="763" height="133">
<label>
ItemId<input name="ItemId" type="text" id="ItemId" value="" size="50" /></br>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
<?php
function makeAWSUrl($parameters, $associate_tag, $access_key, $secret_key, $aws_version = '2009-10-01') {
$host = 'ecs.amazonaws.com';
$path = '/onca/xml';
$query = array(
'Service' => 'AWSECommerceService',
'AWSAccessKeyId' => $access_key,
'AssociateTag' => $associate_tag,
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'Version' => $aws_version,
);
if (is_array($parameters)) {
$query = array_merge($query, $parameters);
}
ksort($query);
$temp = array();
foreach ($query as $k => $v) {
$temp[] = str_replace('%7E', '~', rawurlencode($k)) . '=' . str_replace('%7E', '~', rawurlencode($v));
}
$signable = implode('&', $temp);
$stringToSign = "GET\n$host\n$path\n$signable";
$hex_str = hash_hmac('sha256', $stringToSign, $secret_key);
$raw = '';
for ($i = 0; $i < strlen($hex_str); $i += 2) {
$raw .= chr(hexdec(substr($hex_str, $i, 2)));
}
$query['Signature'] = base64_encode($raw);
ksort($query);
$temp = array();
foreach ($query as $k => $v) {
$temp[] = rawurlencode($k) . '=' . rawurlencode($v);
}
$final = implode('&', $temp);
echo 'http://' . $host . $path . '?' . $final;
echo "<br><br><br>";
return 'http://' . $host . $path . '?' . $final;
}
//rg = ResponseGroup.new( 'Medium', 'Offers', 'Reviews' )
$url = makeAWSUrl(array('Operation' => 'ItemLookup', 'ResponseGroup' => 'Medium', 'ItemId' => $ItemId), $AssociateTag, $public_key, $private_key);
$xml = simplexml_load_file ($url);
print_r($xml);
/*
$ii = 0;
foreach($xml->Items as $results) {
$totalresults = $results->TotalResults;
$totalpages = $results->TotalPages;
echo "<p>Total Results is: $totalresults<br />Total Pages is: $totalpages</p>";
}
echo "<p>$a_nav</p>";
*/
$iii = 0;
foreach($xml->Items->Item as $item) {
//print_r($item)."<br><br>";
$ASIN = $item->ASIN;
$Name = $item->ItemAttributes->Title;
$Brand = $item->ItemAttributes->Brand;
$Model = $item->ItemAttributes->Model;
$ListPrice = $item->ItemAttributes->ListPrice->FormattedPrice;
$LowestNewPrice = $item->OfferSummary->LowestNewPrice->FormattedPrice;
$ProductGroup = $item->ItemAttributes->ProductGroup;
$ProductTypeName = $item->ItemAttributes->ProductTypeName;
$Publisher = $item->ItemAttributes->Publisher;
$Studio = $item->ItemAttributes->Studio;
$SalesRank = $item->SalesRank;
$SmallImage = $item->SmallImage->URL;
$MediumImage = $item->MediumImage->URL;
$LargeImage = $item->LargeImage->URL;
//$ImageSets1 = $item->ImageSets->ImageSet ->LargeImage->URL;
$ImgReview = "";
foreach($item->ImageSets->ImageSet as $results) {
$ImgReview = $ImgReview.$results->LargeImage->URL."<br>";
}
$Feature = "<div class=\"content\">\r\n";
$Feature = $Feature."<ul style=\"LIST-STYLE-TYPE: disc; MARGIN-LEFT: 25px\">\r\n";
foreach($item->ItemAttributes->Feature as $results) {
$Feature = $Feature."<li>".$results."</li>\r\n";
$Feature = $Feature."</ul></div>";
//echo "Feature =$Feature <br />";
//$Description = $item->EditorialReviews->EditorialReview->Content;
//$Description2 = $item->EditorialReviews->EditorialReview->Content[1];
}
foreach($item->EditorialReviews->EditorialReview as $results) {
$Description[] =$results->Content;
//echo "<font color=red>Description</font> = ".$Description;
}
}
$BandMaterialType = $item->ItemAttributes->BandMaterialType;
$BezelMaterialType = $item->ItemAttributes->BezelMaterialType;
/*
echo "<br><br><br><hr>";
echo "ASIN = $ASIN<br />";
echo "Name = $Name <br />";
echo "Brand = $Brand<br />";
echo "Model = $Model<br />";
echo "ListPrice = $ListPrice <br />";
echo "LowestNewPrice = $LowestNewPrice <br />";
echo "ProductGroup = $ProductGroup <br />";
echo "ProductTypeName = $ProductTypeName <br />";
echo "Publisher = $Publisher <br />";
echo "Studio = $Studio <br />";
echo "SalesRank = $SalesRank <br />";
echo "SmallImage = $SmallImage <br />";
echo "MediumImage = $MediumImage <br />";
echo "LargeImage = $LargeImage <br />";
echo "Feature = $Feature <br />";
echo "BandMaterialType = $BandMaterialType <br />";
echo "BezelMaterialType = $BezelMaterialType <br />";
echo "ImgReview = $ImgReview <br />";
*/
?>
</body>
</html>
รับค่ามาแล้วนะครับ แต่มันไม่ขึ้นอะไรเลยอ่ะครับ
|
|
|
|
|
Date :
2013-01-23 11:01:18 |
By :
supachok11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไว้ว่าง ๆ จะมาดูให้ครับ
|
|
|
|
|
Date :
2013-01-23 11:19:58 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับ
|
|
|
|
|
Date :
2015-12-31 20:25:43 |
By :
บอย |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอนนี้น่าจะหมดยุคเฟื่่องฟูของ Amazon แล้วครับ เห็นหลายคนมากกว่า 95% เลิกกันหมดล่ะ
|
|
|
|
|
Date :
2016-01-03 11:36:17 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|