Jump to content

[SOLVED] Parse out list from amazon.com ?


mini_

Recommended Posts

If you look on

http://www.amazon.com/gp/bestsellers/music/ref=pd_ts_c_th_head/002-5957247-9688012?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=right-4&pf_rd_r=1GH6HBJ7B31EPCC5K6XK&pf_rd_t=101&pf_rd_p=259704501&pf_rd_i=5174

it shows the best sellers music albums om amazon.com

Is it possible to use some kind of regexp to parse out the top 25 list shown on the page?

Have been trying for the hole day without any success  :o

 

Any help at all would make me very glad :)

Link to comment
https://forums.phpfreaks.com/topic/45098-solved-parse-out-list-from-amazoncom/
Share on other sites

<pre>
<?php

$url = 'http://www.amazon.com/gp/bestsellers/music/ref=pd_ts_c_th_head/002-5957247-9688012?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=right-4&pf_rd_r=1GH6HBJ7B31EPCC5K6XK&pf_rd_t=101&pf_rd_p=259704501&pf_rd_i=5174';
$page = file_get_contents($url);
preg_match_all('%<strong.+?><a.+?>([^>]+)</a></strong>\s*<br />\s+~\s+((??!\(Artist\))[^<])+)%', $page, $matches, PREG_SET_ORDER);
// Toss full matches.
foreach ($matches as &$match) {
	array_shift($match);
}
print_r($matches);

?>
</pre>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.