1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Pinterest category pin scraper (iMacros script)

Discussion in 'Social Networking Sites' started by 45415, Apr 14, 2012.

Tags:
  1. 45415

    45415 Junior Member

    Joined:
    Feb 5, 2009
    Messages:
    194
    Likes Received:
    92
    Yesterday, one member asked me how do I scrape pins from Pinterest. I sent him my iMacro script that I have been using for a while now. So I thought why not share it with all of you guys.

    I hope some of you will find it useful. :)

    Here is the iMacros script:
    Code:
    SET !VAR1 123456789123456789
    SET !EXTRACT_TEST_POPUP NO
    SET !LOOP 1
    
    URL GOTO=http://pinterest.com/all/?category=food_drink&lazy=1&page={{!LOOP}}&marker={{!VAR1}}
    
    WAIT SECONDS=1
    
    URL GOTO=javascript:function<SP>get()<SP>{<SP><SP>var<SP>desc<SP>=<SP>[];<SP>var<SP>imgurl<SP>=<SP>[];<SP>var<SP>de<SP>=<SP>[];<SP>for<SP>(var<SP>i=0;<SP>i<SP><<SP>document.getElementsByTagName("div").length;<SP>i++)<SP>{<SP><SP><SP>if(document.getElementsByTagName("div")[i].getAttribute("class")=="pin")<SP>{<SP><SP><SP><SP><SP>for(var<SP>j=0;<SP>j<SP><<SP>document.getElementsByTagName("div")[i].getElementsByTagName("img").length;<SP>j++)<SP>{<SP><SP><SP><SP>if(document.getElementsByTagName("div")[i].getElementsByTagName("img")[j].getAttribute("class")<SP>==<SP>"PinImageImg")<SP>{<SP><SP><SP><SP><SP>imgurl[i]<SP>=<SP>document.getElementsByTagName("div")[i].getElementsByTagName("img")[j].src;<SP><SP><SP><SP>}<SP><SP><SP>}<SP><SP><SP><SP><SP><SP>for(var<SP>j=0;<SP>j<SP><<SP>document.getElementsByTagName("div")[i].getElementsByTagName("span").length;<SP>j++)<SP>{<SP><SP><SP><SP>if(document.getElementsByTagName("div")[i].getElementsByTagName("span")[j].getAttribute("class")<SP>==<SP>"RepinsCount")<SP>{<SP><SP><SP><SP><SP>desc[i]<SP>=<SP>document.getElementsByTagName("div")[i].getElementsByTagName("span")[j].innerHTML;<SP><SP><SP><SP>}<SP><SP><SP>}<SP><SP><SP><SP><SP><SP>for(var<SP>j=0;<SP>j<SP><<SP>document.getElementsByTagName("div")[i].getElementsByTagName("p").length;<SP>j++)<SP>{<SP><SP><SP><SP>if(document.getElementsByTagName("div")[i].getElementsByTagName("p")[j].getAttribute("class")<SP>==<SP>"description")<SP>{<SP><SP><SP><SP><SP>de[i]<SP>=<SP>document.getElementsByTagName("div")[i].getElementsByTagName("p")[j].innerHTML;<SP><SP><SP><SP>}<SP><SP><SP>}<SP><SP><SP><SP><SP>}<SP>}<SP><SP>for(var<SP>i=0;i<imgurl.length;<SP>i++)<SP>{<SP><SP>if(typeof<SP>imgurl[i]<SP>!=<SP>"undefined"<SP>&&<SP>typeof<SP>desc[i]<SP>!=<SP>"undefined")<SP>{<SP><SP><SP>document.write("\""<SP>+<SP>imgurl[i].replace("_b.jpg",<SP>"_c.jpg")<SP>+<SP>"\",<SP>"<SP>+<SP>desc[i].replace("<SP>repins  ",<SP>"").replace("<SP>repin  ",<SP>"")<SP>+<SP>",<SP>\""<SP>+<SP>de[i].replace("\"",<SP>"'").replace(",",<SP>"<SP>")<SP>+<SP>"\"\r\n");<SP><SP><SP>}<SP>}<SP>}<SP>get();
    
    TAG POS=1 TYPE=HTML ATTR=* EXTRACT=TXT
    
    SAVEAS TYPE=TXT FOLDER=C:\Users\username\Desktop\csv\data FILE=out{{!LOOP}}.csv
    
    How to use the script?
    Simply run the script in a loop with Internet Explorer iMacros add-on. I tried it with Firefox, but I couldn't execute the Javascript code, so I switched to IE.
    On the first line you have to set the id of the newest pin from a category you choose.
    Then you want to change the URL. In this example I am using Food & Drink category. Just go to any Pinterest category page and see the URL yourself.
    Then comes the Javascript part. It grabs all the images, descriptions and number of repins and then displays image url, number of repins and description of pins with at least 1 repin.
    In the last line you can choose a folder where to save all the csv files.


    I usually run the script in a loop for 50 times, so I get 50 csv files.
    After that I merge them running this bat file from my csv folder:
    Code:
    copy data\*.csv all.txt
    
    Now you have a text file with all the information. You can use Excel to sort lines by number of repins and find out currently the most popular pins from a specific category.

    Enjoy! :)
     
    • Thanks Thanks x 5
  2. Executer

    Executer Junior Member

    Joined:
    Aug 16, 2009
    Messages:
    110
    Likes Received:
    8
    this saves all the html data not just the # of re-pins/description/likes.....
     
  3. 45415

    45415 Junior Member

    Joined:
    Feb 5, 2009
    Messages:
    194
    Likes Received:
    92
    On which browser did you test it?
    I have been using this script and it still works most of the time - sometimes it can't go past page 1 (probably something on the Pinterest side is wrong), but even in that case this script will show url, repins, description.


    Changed the   replacing to remove white space:
    Code:
    SET !VAR1 123456789123456789
    SET !EXTRACT_TEST_POPUP NO
    SET !LOOP 1
    
    URL GOTO=http://pinterest.com/all/?category=food_drink&lazy=1&page={{!LOOP}}&marker={{!VAR1}}
    
    WAIT SECONDS=1
    
    URL GOTO=javascript:function<SP>get()<SP>{<SP><SP>var<SP>desc<SP>=<SP>[];<SP>var<SP>imgurl<SP>=<SP>[];<SP>var<SP>de<SP>=<SP>[];<SP>for<SP>(var<SP>i=0;<SP>i<SP><<SP>document.getElementsByTagName("div").length;<SP>i++)<SP>{<SP><SP><SP>if(document.getElementsByTagName("div")[i].getAttribute("class")=="pin")<SP>{<SP><SP><SP><SP><SP>for(var<SP>j=0;<SP>j<SP><<SP>document.getElementsByTagName("div")[i].getElementsByTagName("img").length;<SP>j++)<SP>{<SP><SP><SP><SP>if(document.getElementsByTagName("div")[i].getElementsByTagName("img")[j].getAttribute("class")<SP>==<SP>"PinImageImg")<SP>{<SP><SP><SP><SP><SP>imgurl[i]<SP>=<SP>document.getElementsByTagName("div")[i].getElementsByTagName("img")[j].src;<SP><SP><SP><SP>}<SP><SP><SP>}<SP><SP><SP><SP><SP><SP>for(var<SP>j=0;<SP>j<SP><<SP>document.getElementsByTagName("div")[i].getElementsByTagName("span").length;<SP>j++)<SP>{<SP><SP><SP><SP>if(document.getElementsByTagName("div")[i].getElementsByTagName("span")[j].getAttribute("class")<SP>==<SP>"RepinsCount")<SP>{<SP><SP><SP><SP><SP>desc[i]<SP>=<SP>document.getElementsByTagName("div")[i].getElementsByTagName("span")[j].innerHTML;<SP><SP><SP><SP>}<SP><SP><SP>}<SP><SP><SP><SP><SP><SP>for(var<SP>j=0;<SP>j<SP><<SP>document.getElementsByTagName("div")[i].getElementsByTagName("p").length;<SP>j++)<SP>{<SP><SP><SP><SP>if(document.getElementsByTagName("div")[i].getElementsByTagName("p")[j].getAttribute("class")<SP>==<SP>"description")<SP>{<SP><SP><SP><SP><SP>de[i]<SP>=<SP>document.getElementsByTagName("div")[i].getElementsByTagName("p")[j].innerHTML;<SP><SP><SP><SP>}<SP><SP><SP>}<SP><SP><SP><SP><SP>}<SP>}<SP><SP>for(var<SP>i=0;i<imgurl.length;<SP>i++)<SP>{<SP><SP>if(typeof<SP>imgurl[i]<SP>!=<SP>"undefined"<SP>&&<SP>typeof<SP>desc[i]<SP>!=<SP>"undefined")<SP>{<SP><SP><SP>document.write("\""<SP>+<SP>imgurl[i].replace("_b.jpg",<SP>"_c.jpg")<SP>+<SP>"\",<SP>"<SP>+<SP>desc[i].replace("<SP>repins",<SP>"").replace("<SP>repin",<SP>"")<SP>+<SP>",<SP>\""<SP>+<SP>de[i].replace("\"",<SP>"'").replace(",",<SP>"<SP>")<SP>+<SP>"\"\r\n");<SP><SP><SP>}<SP>}<SP>}<SP>get();
    
    TAG POS=1 TYPE=HTML ATTR=* EXTRACT=TXT
    
    SAVEAS TYPE=TXT FOLDER=C:\Users\username\Desktop\csv\data FILE=out{{!LOOP}}.csv
    
     
  4. kainth56

    kainth56 Registered Member

    Joined:
    Jul 23, 2009
    Messages:
    70
    Likes Received:
    45
    Can you make one for ripping user url ID for pinterest just like above.