I need to extract the ID
of products from Amazon
. I am developing a small application to calculate the cost of buying and shipping products from online stores. He had managed to bring the information with cURL
and XPath
. With Amazon
it did not work for me, so I found a library to use ItemLookUp
(API AMAZON) with the ID
of the product. As the way the application will work is by pasting the product link, I need some way to extract that information from the link (ID).
Example:
https://www.amazon.com/TotalMount-PlayStation-Slim-Mounts-wall-near/dp/B07281WC5W/ref=sr_1_2?s=videogames&ie=UTF8&qid=1497043401&sr=1-2-spons&keywords=playstation&psc=1
The data I need to extract is what is inside /dp/IDPRODUCTO/ ->B07281WC5W
. Is there any function in PHP
that allows me to extract that data? Already with that data I would complete my last puzzle piece.
I work the options that have given me but I've noticed that the Amazon link has 3 variations, so I'll have to make my changes, when I've adapted it to the application I'll tell you how to stay at the end.
Thank you.
Well, it worked for me and I adapted it to what I was developing, the variation was that I saw some products that did not have the same format in the link and then did not return any data.
require_once( "AmazonAPI.php");
$enlace = ($_POST["cotizar"]);
$amazonAPI = new AmazonAPI('YOUR API KEY', 'YOUR SECRET KEY', 'YOUR ASSOCIATE TAG' );
$amazonAPI->SetRetrieveAsArray();
$listado = explode("/", $enlace);
$sku = $listado[5];
$items = $amazonAPI->ItemLookUp( $sku );
foreach ($items as $item) {
return $item ;
}
More or less like that. On a cell phone you have a / more so I put a conditional to detect mobile and $ sku = $ listing [6];
Thanks for the help.