Hi,, I am learning php for fun and have set myself a project to write a php script that when run does this: goes to amazon.co.uk searches for item you specified eg item number 123456 'finds' the price on the page copies and pastes the current price to a txt file the 3rd part, where the code locates the price on the page is probably the trickiest - any suggestions how to go about this?
lol nice. Sounds hard, even for me, since I'm new to PHP too. I think it's possible with cURL. I made something that grabs the whole HTML page with it. Anyway, I'm sure there's better function than cURL. How far are you with PHP anyways? You should start with simple PHP+mySQL if you're a total beginner with programming.
It is very hard and I would not recommend attempting it if you're an absolute beginner. You will need to sign up as an Amazon affiliate. Access their affiliate servers using REST/SOAP (web services) You can find the documentation here of the requests you can make. And that is not all; The requests have to be signed which is a very complex task, working with the returned data (XML) which requires to be good at problem solving, etc. The overall task is requires someone with a very advanced knowledge in PHP and XML.
it is damn simple.. use php curl then use preg match after observing the source code of the webpage now you have the price in variable just store it
I agree with phpl0v3r's solution. This is merely identifying right place on page to match using preg_match and you will have the price value with you
You can use curl with PHP and try and scrape the page as others have suggested, or you can use the DOM, i.e. get 'simplehtmldom' class. It will make things MUCH easier.
<?php //item to search... $item = '123456'; //searches @ amazon... $amazon = file_get_contents('http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords='.urlencode($item).'&x=15&y=14&ih=1_0_0_0_0_0_0_0_0_1.418_18&fsc=-1'); //find the price... if (preg_match('~<a href="http://www\.amazon\.com/.+?">Buy new</a>: <span>([\$0-9\.]+)</span></div>\s*<div class="usedPrice"> </div>~', $amazon, $a)) { $price = $a[1]; echo $price; //use fwrite() to write $price to txt file... } ?> PHP:
Just so you know, using their api does not require regex, they provide all the abstraction layer. So why waste your own cpu power when you can use theirs.
True but its the equivalent in doing so, but in a more convenient way. (It saves your writing the regex, but not using it.) Also, I'd post up an example on how to use the amazon api up unfourtanetly im unfamiliar with it never used amazon nor their api, but as its an api i assume it would'nt be too hard to use - as it would have documentation an examples.
Yeah if your going to be working with the Amazon I totally recomend using the API so much easier to use than parsing the HTML https: //affiliate-program.amazon.com/gp/advertising/api/detail/main.html#resources <----- I just signed up so I can't post links remove the space after the colon I use this API whenever I have to work with Amazon and there are some samples in there to help you get started, but it all depends at what level you are. If you have any questions hit me up!