title: Parsing URLs that need authentication, cookies - python beautifulsoup
body: <p><a href="https://example.net/users/101" rel="nofollow">https://example.net/users/101</a> </p>
  
  <p>The login page has a form with username &amp; password. I used both urllib.request &amp; http.cookiejar. I'm still not able to extract contents from that URL. Please help. Thanks in advance.</p>
  
  <p>Code using urllib.request: </p>
  
  <pre><code>import urllib.request
  opener = urllib.request.FancyURLopener()
  print(opener.open('http://username:password@example.net/').read())
  </code></pre>
  
  <p>Code using http.cookiejar:</p>
  
  <pre><code>import requests,http.cookiejar,urllib.request,os
  username = 'username'
  password = 'password'
  cj = http.cookiejar.CookieJar()
  opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
  login_data = urllib.parse.urlencode({'username' : username, 'password' : password})
  binary_data = login_data.encode('ascii')
  resp = opener.open('https://example.net/users/101', binary_data)
  print(resp)
  </code></pre>