<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Grohs Fabian</title>
    <description>The latest articles on DEV Community by Grohs Fabian (@grohsfabian).</description>
    <link>https://dev.to/grohsfabian</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F7738%2F_-ealO82.jpg</url>
      <title>DEV Community: Grohs Fabian</title>
      <link>https://dev.to/grohsfabian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/grohsfabian"/>
    <language>en</language>
    <item>
      <title>Coding an Instagram Like Bot with NodeJs</title>
      <dc:creator>Grohs Fabian</dc:creator>
      <pubDate>Mon, 14 Jan 2019 18:01:57 +0000</pubDate>
      <link>https://dev.to/grohsfabian/coding-an-instagram-like-bot-with-nodejs-l50</link>
      <guid>https://dev.to/grohsfabian/coding-an-instagram-like-bot-with-nodejs-l50</guid>
      <description>&lt;p&gt;Hey there to everyone,&lt;/p&gt;

&lt;p&gt;I just wanted to share this here because maybe someone can learn something from it.&lt;/p&gt;

&lt;h1&gt;
  
  
  What? 💻
&lt;/h1&gt;

&lt;p&gt;Yes, I've built an Instagram bot that basically does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Opens up the Instagram Login page&lt;/li&gt;
&lt;li&gt;Logs in with specific &lt;strong&gt;username&lt;/strong&gt; and &lt;strong&gt;password&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Goes through an &lt;strong&gt;[array]&lt;/strong&gt; of tags and loops over them to get the latest 3 images&lt;/li&gt;
&lt;li&gt;Click on the images, like them, close the modal &lt;/li&gt;
&lt;li&gt;AND REPEAT UNTIL IS STOPPED.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Why?
&lt;/h1&gt;

&lt;p&gt;For fun and for educational purposes only, I do not recommend you to use this code in order to spam Instagram.&lt;/p&gt;

&lt;p&gt;Therefore this time, I did not give out the Full Code.&lt;/p&gt;

&lt;h1&gt;
  
  
  How?
&lt;/h1&gt;

&lt;p&gt;Here is how,&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;40+ minutes&lt;/strong&gt; video that I just recorded in about &lt;strong&gt;4 hours&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy 🔥&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/jw4exv4qv2E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Ps: I also post more about NodeJs and Data Scraping on my blog -&amp;gt; &lt;strong&gt;&lt;a href="https://learnscraping.com"&gt;LearnScraping.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>instagram</category>
      <category>node</category>
      <category>puppeteer</category>
      <category>scraping</category>
    </item>
    <item>
      <title>Start Web Scraping with NodeJs</title>
      <dc:creator>Grohs Fabian</dc:creator>
      <pubDate>Tue, 27 Nov 2018 23:36:15 +0000</pubDate>
      <link>https://dev.to/grohsfabian/start-web-scraping-with-nodejs--4l62</link>
      <guid>https://dev.to/grohsfabian/start-web-scraping-with-nodejs--4l62</guid>
      <description>&lt;p&gt;Hey there,&lt;/p&gt;

&lt;p&gt;Today we're gonna get started with Web Scraping with NodeJs with some &lt;strong&gt;cool and simple examples&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's get started&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;I'm not going to make it boring for you with scientific technical explanation so,&lt;/p&gt;

&lt;p&gt;I'm gonna give you a simple example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lets say&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You want to get information of a instagram profile, followers, followings, uploads, description and other informations which may not be available to an API or you may not have access to that API.&lt;/p&gt;

&lt;p&gt;This is the case that you go and start with Web Scraping.&lt;/p&gt;

&lt;h1&gt;
  
  
  💻 Tools we're gonna use
&lt;/h1&gt;

&lt;p&gt;Here are the tools that I am going to use for this example, these are the perfect tools for getting started&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/request/request" rel="noopener noreferrer"&gt;Request&lt;/a&gt; - Peer dependency for &lt;strong&gt;request-promise&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/request/request-promise" rel="noopener noreferrer"&gt;Request-Promise&lt;/a&gt; - In order to make the requests and to get the contents of the website you want to scrape.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/cheeriojs/cheerio" rel="noopener noreferrer"&gt;Cheerio&lt;/a&gt; - Probably the most used library to parse html content with NodeJs with a &lt;strong&gt;Jquery-like syntax&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Nothing else. Yes, that's right!&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;I will assume that you already have &lt;a href="http://nodejs.org" rel="noopener noreferrer"&gt;Node.Js&lt;/a&gt; installed on your laptop or pc and if not, what are you waiting for? 🔥&lt;/p&gt;

&lt;p&gt;Now, we need to make sure that you have a new project ready to write the code.&lt;/p&gt;

&lt;p&gt;You can easily initiate one on a new empty folder with &lt;strong&gt;npm&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And after completing these steps you must install the libraries that we're gonna use by running the following lines ( while on the same new project ):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install cheerio --save&lt;br&gt;
npm install --save request&lt;br&gt;
npm install request-promise --save&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  What are we scraping? 🤔
&lt;/h1&gt;

&lt;p&gt;For this example I am going to take this community website &lt;strong&gt;dev.to&lt;/strong&gt; because I want to make this unique and directly dedicated to all you people 😋&lt;/p&gt;

&lt;p&gt;We're gonna scrape basic details of any &lt;strong&gt;dev.to&lt;/strong&gt; member page.&lt;/p&gt;
&lt;h1&gt;
  
  
  Mentions
&lt;/h1&gt;

&lt;p&gt;I very much want to mention that if you still Web Scrape with callbacks or chained promises, this is going to be a nice refresh to you because we are going to use &lt;strong&gt;async await syntax&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I also post a lot content like this on my &lt;strong&gt;&lt;a href="https://learnscraping.com/" rel="noopener noreferrer"&gt;Scraping Blog&lt;/a&gt;&lt;/strong&gt; including a nice article on &lt;a href="https://learnscraping.com/scraping-instagram-profile-data-with-nodejs/" rel="noopener noreferrer"&gt;Scraping Instagram Profile Data with NodeJs&lt;/a&gt; 💻&lt;/p&gt;
&lt;h1&gt;
  
  
  Lets Code 👨‍💻👩‍💻
&lt;/h1&gt;

&lt;p&gt;Let's get right at it, I don't like to waste time talking non sense without actually showing some code and results.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Initial request and parsing
&lt;/h2&gt;

&lt;p&gt;The first phase is pretty straight forward. We need to simulate a request to the &lt;em&gt;dev.to&lt;/em&gt; website just like a normal browser would and get the HTML content of it.&lt;/p&gt;

&lt;p&gt;Here's what you can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const request = require('request-promise');
const cheerio = require('cheerio');

const BASE_URL = 'https://dev.to/';
const USERNAME = 'grohsfabian';

(async () =&amp;gt; {

  /* Send the request to the user page and get the results */
  let response = await request(`${BASE_URL}${USERNAME}`);

  /* Start processing the response */
  let $ = cheerio.load(response);

  /* Parse details from the html with query selectors */
  let fullName = $('span[itemprop="name"]').text();

  console.log({ fullName });

})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I really do think that this code is pretty self explanatory if you look at it even for someone who doesn't know much about scraping or maybe nothing at all.&lt;/p&gt;

&lt;p&gt;This example shows you how easy you can get someone's &lt;strong&gt;Full Name&lt;/strong&gt; from their profile page of the &lt;em&gt;dev.to&lt;/em&gt; website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenyf529iq77dyljpo34e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenyf529iq77dyljpo34e.png" alt="first" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pretty cool?&lt;/em&gt; &lt;strong&gt;Let's move further 👁&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Getting more data
&lt;/h2&gt;

&lt;p&gt;Now, that we have a base to start off, we need to continue to do the same things but for the other data from the Profile that we want to get.&lt;/p&gt;

&lt;p&gt;Again, because we are using &lt;strong&gt;Cheerio&lt;/strong&gt; as the method for parsing the html, we can use any selector from the jquery library that is integrated into Cheerio.&lt;/p&gt;

&lt;p&gt;So, this means that you should at least have some basic knowledge of &lt;a href="https://www.w3schools.com/cssref/css_selectors.asp" rel="noopener noreferrer"&gt;CSS Query Selectors&lt;/a&gt; ( which you can use in Cheerio ) and also &lt;a href="https://api.jquery.com/category/selectors/" rel="noopener noreferrer"&gt;Jquery Selectors&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  So, before going any further..
&lt;/h3&gt;

&lt;p&gt;I want to at least break down the selector that we are using for &lt;strong&gt;getting the Full Name&lt;/strong&gt; of the profile.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;span[itemprop="name"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This tells the cheerio library to look for: The HTML element that is a &lt;strong&gt;span&lt;/strong&gt; which has the &lt;strong&gt;itemprop attribute&lt;/strong&gt; AND that attribute &lt;strong&gt;is equal to "name"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We are going to use the same structure and logic for the further selectors 💻.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lets create.
&lt;/h3&gt;

&lt;p&gt;I've made a few more selectors in order to parse more data from the profile and here it is 🔥&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let description = $('span[itemprop="description"]').text();
let profilePictureUrl = $('img[class="profile-pic"]').attr('href');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is just the start. These are some simple examples that are pretty easy to get and don't require much thinking.&lt;/p&gt;

&lt;h3&gt;
  
  
  Going a bit deeper.
&lt;/h3&gt;

&lt;p&gt;Here are some interesting informations that could be a little bit more challenging for a beginner to get but still, a nice exercise.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fguwob20q2cjsg1e35p1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fguwob20q2cjsg1e35p1s.png" alt="second" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These details right here can be existing and can be not there. People can either add their email to be public or not, it's their choice. But still, it is our option to be able to scrape everything that we want. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Here's what I'm gonna do..&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  /* Get extra properties from the profile */
  let details = {};

  $('div[class="user-metadata-details-inner"] &amp;gt; div[class="row"]').each((i, elm) =&amp;gt; {

    let key = $(elm).find('div[class="key"]').text().trim();
    let value = $(elm).find('div[class="value"]').text().trim();

    details[key] = value;
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This piece of code is going to iterate over all the possible properties of the profile, which include stuff like &lt;strong&gt;Joined date&lt;/strong&gt;, &lt;strong&gt;email&lt;/strong&gt; ( if available ), ** location ** ( if available )..etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting another round of details
&lt;/h3&gt;

&lt;p&gt;We're not stopping here, I'm going even deeper with this to &lt;strong&gt;get all the social links&lt;/strong&gt; available to the persons page.&lt;/p&gt;

&lt;p&gt;I'm gonna use a similar technique that I've used above and here is what it's going to look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  /* Get socials from the profile */
  let socials = [];
  $('p[class="social"] &amp;gt; a').each((i, elm) =&amp;gt; {

    let url = $(elm).attr('href');

    socials.push(url);
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in this code I'm basically iterating over each of the links available in that class that includes the social icon buttons and storing them in an array.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Finishing it
&lt;/h2&gt;

&lt;p&gt;Of course, a lot more data can be scraped depending on your needs but I think you get the point now..&lt;/p&gt;

&lt;p&gt;Scraping is a nice skill to have and if you know the basics of it then it opens up your imagination of what you can do 🔥&lt;/p&gt;

&lt;h1&gt;
  
  
  Full Code
&lt;/h1&gt;

&lt;p&gt;TL;DR; Here's everything you need if you didn't want to read the article 😅&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const request = require('request-promise');
const cheerio = require('cheerio');

const BASE_URL = 'https://dev.to/';
const USERNAME = 'peter';

(async () =&amp;gt; {

  /* Send the request to the user page and get the results */
  let response = await request(`${BASE_URL}${USERNAME}`);

  /* Start processing the response */
  let $ = cheerio.load(response, { normalizeWhitespace: true });

  /* Parse details from the html */
  let fullName = $('span[itemprop="name"]').text();
  let description = $('span[itemprop="description"]').text();
  let profilePictureUrl = $('img[class="profile-pic"]').attr('href');

  /* Get extra properties from the profile */
  let details = {};

  $('div[class="user-metadata-details-inner"] &amp;gt; div[class="row"]').each((i, elm) =&amp;gt; {

    let key = $(elm).find('div[class="key"]').text().trim();
    let value = $(elm).find('div[class="value"]').text().trim();

    details[key] = value;
  });

  /* Get socials from the profile */
  let socials = [];
  $('p[class="social"] &amp;gt; a').each((i, elm) =&amp;gt; {

    let url = $(elm).attr('href');

    socials.push(url);
  });

  console.log({
    fullName,
    profilePictureUrl,
    description,
    details,
    socials
  });

})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code is going to output you something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg848xim5dwc4q3tpd4lb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg848xim5dwc4q3tpd4lb.png" alt="image" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But please do NOT use this code for malicious intent and spamming!&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Video Tutorial
&lt;/h1&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/SLqASSu4-Q4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  The Plug
&lt;/h1&gt;

&lt;p&gt;*Here comes the plug people.. *&lt;/p&gt;

&lt;p&gt;I have recently launched my new Blog dedicated to help you &lt;strong&gt;learn more about scraping with NodeJs&lt;/strong&gt; and I have some good articles there and in-depth like this one.&lt;/p&gt;

&lt;p&gt;Make sure to check it out, I'm sure you will like it -&amp;gt; &lt;a href="https://learnscraping/" rel="noopener noreferrer"&gt;LearnScraping with NodeJs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're really liking this kind of stuff, I also have a great &lt;strong&gt;5 Star Course&lt;/strong&gt; and &lt;strong&gt;best seller on Udemy&lt;/strong&gt;. Also,&lt;/p&gt;

&lt;p&gt;I have a &lt;strong&gt;secret coupon&lt;/strong&gt; for all the dev.to members&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.udemy.com/nodejs-web-scraping/?couponCode=DEVTOX" rel="noopener noreferrer"&gt;Learn Web Scraping with NodeJs - The Crash Course&lt;br&gt;
&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Ask me anything and please let me know what you thought about the article 🔥&lt;/p&gt;

</description>
      <category>scraping</category>
      <category>node</category>
      <category>webscraping</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
