title: Logging in to Instagram without Selenium
body: <p>I'm trying to get the page source for an Instagram post using the code below. Funnily enough, it worked a few times but then it said that I wasn't logged in (which changes the entire source code). Is there any way so that I can access the source code? You would get while logged in without using automation stuff like Selenium, because that would be pretty slow.</p>
  <pre><code>import requests
  import urllib
  from urllib.request import urlopen, URLError, Request
  
  
  def getSource(rawLink):
  
      req = Request(
          rawLink,
          data = None,
          headers = {
              &quot;User-Agent&quot;: &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36&quot;
          }
      )
  
      with urlopen(req) as response:
  
          source = response.read().decode('utf-8')
  
      return source
  
  
  link = &quot;https://www.instagram.com/p/COF47v4HoC9/&quot;
  source = getSource(link)
  
  print(source[0:100])
  </code></pre>
  <p>As you can see the output line <code>&lt;html lang=&quot;en&quot; class=&quot;no-js not-logged-in client-root&quot;&gt;</code> indicates how I'm not logged in.</p>