• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » PHP » Quickly Build Amazon ASIN Grabber with Simple Html DOM

Quickly Build Amazon ASIN Grabber with Simple Html DOM

By Sigit Prasetya Nugroho ∙ July 28, 2014 ∙ PHP ∙ 7 Comments

Share : TwitterFacebookTelegramWhatsapp

In my last article Easy Build Amazon ASIN Grabber with PHP and Curl, now i will share about how to use Simple HTML DOM to grab asin from amazon site. Basically, the concept is same, grab HTMLs element, but with Simple HTML DOM function , the script will be more simpler. Visit PHP Simple HTML DOM if you want to learn more about simple html DOM.

What is PHP Simple HTML DOM Parser ? From the site, The description, requirement & features is

  • A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
  • Require PHP 5+.
  • Supports invalid HTML.
  • Find tags on an HTML page with selectors just like jQuery.
  • Extract contents from HTML in a single line.

Okay lets start the experiment.

  • Download Simple Html DOM function here
  • Create php file with name asin_dom.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
include "simple_html_dom.php";
$html = file_get_html('http://www.amazon.com/s/ref=nb_sb_noss_2/176-0876229-3718769?url=search-alias%3Daps&field-keywords=iphone');
$no=1;
echo '<table border="1" style="border-collapse:collapse;border-spacing:0;border-color:#aabcfe;"><tr><td align="center">NO</td><td align="center" class="tg-g91i">ASIN</td><td align="center" class="tg-g91i">TITLE</td></tr>';
foreach($html->find('a') as $element)
{
$asin='';
$title='';
foreach ($element->find('span') as $node1)
{
  if ($node1->class=='lrg bold')
  {
    foreach ($node1->find('text') as $node)
    {
       if ($node->parent() === $node1 && strlen($t = trim($node->plaintext)))
       {
           $url = $element->href;
           $hasil=explode("/",$url);
           if (count($hasil)>=5)
           {
              if ($hasil[4]=='dp')
              {
                 $asin=$hasil[5];
              }
           }
           $title = $t ;
           echo '<tr><td align="center">'.$no.'</td><td>'.$asin.'</td><td>'.$title.'</td></tr>';
           $no++;
        }
    }
}
}
}
echo '</table>';

Table of Contents

  • 1  How Amazon ASIN Grabber with Simple Html DOM work ? 
    • 1.1 Congratulation, you create your amazon asin grabber with simple html dom.
    • 1.2 This script is not function again, for new release of this script, please visit https://seegatesite.com/easy-get-asin-with-my-amazon-asin-grabber-class/

 How Amazon ASIN Grabber with Simple Html DOM work ? 

  • You must include simple_html_dom.php on the first.

1
include "simple_html_dom.php";

  • Scrap HTML element with

1
$html = file_get_html('<span style="color: #ff0000;">http://www.amazon.com/s/ref=nb_sb_noss_2/176-0876229-3718769?url=search-alias%3Daps&amp;field-keywords=iphone</span>');

  • Next, you must examine the pattern of ASIN code layout on the amazon html element. in example,

We will grab iphone product in amazon. We get url ” http://www.amazon.com/s/ref=nb_sb_noss_2/176-0876229-3718769?url=search-alias%3Daps&field-keywords=iphone ” open with your browser , ( in this case i use chrome browser ). And then right click and choose view page source . Examine the line of code until you find the same pattern and sequence as follows

Related Articles :

  • How to Create Autocomplete Amazon Keyword Suggestion With Jquery
  • Easy Get XML Amazon API Data with My Amazon_Class
  • Easy Get ASIN with My Amazon Asin Grabber Class

1
2
3
4
5
6
7
8
&lt;h3 class="newaps"&gt;
&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;a href="http://www.amazon.com/Apple-iPhone-16GB-Black-Verizon/dp/B004ZLV5UE/ref=sr_1_1?ie=UTF8&amp;amp;qid=1406514795&amp;amp;sr=8-1&amp;amp;keywords=iphone"&gt;&lt;/span&gt;
&lt;span style="color: rgb(255, 0, 0);"&gt;<span style="color: #ff00ff;">&lt;span class="lrg bold"&gt;</span>Apple iPhone 4 16GB (Black) - CDMA Verizon&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;
&lt;span class="med reg"&gt;by Apple (Sep 3, 2011)&lt;/span&gt;
&lt;/h3&gt;&lt;ul class="rsltL"&gt;
...........
&lt;span style="color: #ff0000;"&gt; &lt;a href="http://www.amazon.com/Apple-iPhone-8GB-White-Verizon/dp/B0074R1IP8/ref=sr_1_3?ie=UTF8&amp;amp;qid=1406514795&amp;amp;sr=8-3&amp;amp;keywords=iphone"&gt;&lt;/span&gt;
&lt;span style="color: #ff0000;"&gt;<span style="color: #ff00ff;">&lt;span class="lrg bold"&gt;</span>Apple iPhone 4 8GB (White) - Verizon&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;

Find a href element contains <span class=”lrg bold”> , with that code  we will get url and the title. Use this script to grab that patern.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</span>
 
foreach($html->find('a') as $element)
{
$asin='';
$title='';
foreach ($element->find('span') as $node1)
{
if ($node1->class=='lrg bold')
{
foreach ($node1->find('text') as $node)
{
if ($node->parent() === $node1 && strlen($t = trim($node->plaintext)))
{
$url = $element->href;
$hasil=explode("/",$url);
if (count($hasil)>=5)
{
if ($hasil[4]=='dp')
{
$asin=$hasil[5];
}
}
$title = $t ;
echo '<tr><td align="center">'.$no.'</td><td>'.$asin.'</td><td>'.$title.'</td></tr>';
$no++;
}
}
}
}
}
 
<span style="color: #000000; font-family: inherit; font-size: 1rem; line-height: inherit;">

Congratulation, you create your amazon asin grabber with simple html dom.

You can develop the script to scrap the Amazon product description, price, etc. Contact us is you need to learn more.

This script is not function again, for new release of this script, please visit https://seegatesite.com/easy-get-asin-with-my-amazon-asin-grabber-class/

Click Here to try Amazon ASIN Grabber with Simple Html DOM.

Another PHP Related Post :

  • How To Replace String With Another String In PHP
  • Login Page – Tutorial CRUD Client and API Server Using JQuery And Lumen Part 2
  • Tutorial CRUD Client and API Server Using JQuery And Lumen Part 1
  • How To Solve Problems Illegal mix of collations (latin1_swedish_ci,IMPLICIT) In Laravel
  • How To Resolve No ‘Access-Control-Allow-Origin’ Header In Lumen
  • How To Create Custom Class In Laravel 5.5 For Beginners

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Comments

  1. Avatar for ismanuddinismanuddin says

    November 13, 2014 at 1:56 am

    Dear Admin,
    In source code from url : hxxp://www.amazon.com/s/ref=nb_sb_noss_2/176-0876229-3718769?url=search-alias%3Daps&field-keywords=iphone ”.

    I’n not find a href element contains , help me please

    Thankyou
    ismanuddin

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      November 13, 2014 at 3:13 am

      I think amazon change the css, try this code

      include “simple_html_dom.php”;
      $html = file_get_html(‘http://www.amazon.com/s/ref=nb_sb_noss_2/176-0876229-3718769?url=search-alias%3Daps&field-keywords=iphone’);
      foreach ($html->find(‘li[class=s-result-item]’) as $node1)
      {
      foreach($node1->find(‘a’) as $linku)
      {
      $url=$linku->href;
      $hasil=explode(“/”,$url);
      if (count($hasil)>=5)
      {
      if ($hasil[4]==’dp’)
      {
      echo $hasil[5].’
      ‘;
      }
      }
      }
      }

      🙂

      Reply
      • Avatar for ismanuddinismanuddin says

        November 13, 2014 at 4:20 pm

        Is the above code using : span , there is a change or not used ?

        Reply
        • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

          November 14, 2014 at 1:17 am

          not used…the basic using simple_html_dom is you must be careful in looking for html attributes (with right click and view pagesource).
          change the code with new example code in the comment.
          If you have difficulty to use simple_html_dom, please try my tutorial grab asin using curl, its still working

          Reply
          • Avatar for ismanuddinismanuddin says

            November 15, 2014 at 3:09 pm

            thank you

  2. Avatar for Usama JafriUsama Jafri says

    May 5, 2015 at 12:13 pm

    Can We Get The Variation Of A Parent ASIN Using PHP.??

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      May 7, 2015 at 4:17 pm

      Helo Usama Jafri,
      Sory, i dont know what you need, but you can try my another asin grabber class script here https://seegatesite.com/easy-get-asin-with-my-amazon-asin-grabber-class/ 🙂

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (7) Publisher Tips (5) react (3) Reactjs (7) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) widget (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2021 Seegatesite.com