title: Instagram scraping
body: <p>The following code is working on a computer to scrape data from Instagram account.
  When I try to use it on a VPS server I'm redirected to the Instagram Login page so the script doesn't work.</p>
  
  <p>Why does Instagram doesn't react the same way when I'm on a computer or on a server ?</p>
  
  <p>It's the same with wget. On a computer I have the profile page, on a server I'm redirected to the login page.</p>
  
  <pre><code>import requests
  import re
  
  
  class InstagramScraper:
      """
      Scraper of Instagram profiles infos.
      """
  
      def __init__(self, session: requests.Session, instagram_account_name: str):
          self.session = session
          self._account_name = self.clean_account_name(instagram_account_name)
          self.load_data()
  
      def load_data(self):
          #print(self._account_name)
          response = self.session.get("https://www.instagram.com/{account_name}/".format(account_name=self._account_name))
          #print(response)
          #print(response.text)
          publications_regex = r'"edge_owner_to_timeline_media":{"count":(\d*),'
          self._publications = re.search(publications_regex, response.text).group(1)
  
          followers_regex = r'"edge_followed_by":{"count":(\d*)'
          self._followers = re.search(followers_regex, response.text).group(1)
  
          # title_regex = r'"@type":".*","name":"(.*)",'
          title_regex = r'"full_name":"(.*)",'
          self._title = re.search(title_regex, response.text).group(1)
          self._title = self._title.split('\"')[0]
  
          following_regex = r'"edge_follow":{"count":(\d*)}'
          self._following = re.search(following_regex, response.text).group(1)
  
      def clean_account_name(self, value) -&gt; str:
          """
          Return the account name without the url address.
          """
          found: str = re.search("https://www.instagram.com/(.*)/", value)
          if found:
              return found.group(1)
          return value
  
      @property
      def publications(self) -&gt; int:
          """
          Number of publications by this account.
          """
          return self._publications
  
      @property
      def followers(self) -&gt; int:
          """
          Number of followers of this account.
          """
          return self._followers
  
      @property
      def title(self) -&gt; str:
          """
          Name of the Instagram profile.
          """
          return self._title
  
      @property
      def account(self) -&gt; str:
          """
          Account name used on Instagram.
          """
          return self._account_name
  
      @property
      def following(self) -&gt; int:
          """
          Number of accounts this profile is following.
          """
          return self._following
  
      def __str__(self) -&gt; str:
          return str({
              'Account': self.account,
              'Followers': self.followers,
              'Publications': self.publications,
              'Following': self.following,
              'Title': self.title,
          })
  
  
  if __name__ == "__main__":
      with requests.session() as session:
          scraper = InstagramScraper(session, "https://www.instagram.com/ksc_lokeren/")
          print(scraper)
  </code></pre>