title: Open URL using python requests only then proceed to download file
body: <p>I'm trying to download a file from a website using Python's request module.</p>
  
  <p>However the site will allow me to download the file only if the download link is clicked directly from the download page. 
  So using requests, I tried hitting the download page's URL first using <code>requests.get()</code> then proceeding to download the file. But unfortunately this doesn't seem to work. A text asking me to open the download page first simply gets written into file.torrent"</p>
  
  <pre><code>import requests
  
  def download(username, password):
      with requests.Session() as session:
          session.post('https://website.net/forum/login.php', data={'login_username': username, 'login_password': password})
  
          # Download page URL
          requests.get('https://website.net/forum/viewtopic.php?t=2508126')
  
          # The download URL itself
          response = requests.get('https://website.net/forum/dl.php?t=2508126')
  
          with open('file.torrent', 'wb') as f:
              f.write(response.content)
  
  download(username='XXXXX', password='YYYYY')
  </code></pre>
  
  <p>Response when downloading directly from the download page (works) :</p>
  
  <pre><code>General :
  Request URL: https://website.net/forum/dl.php?t=2508126
  Request Method: GET
  Status Code: 200 OK
  Remote Address: 185.37.128.136:443
  Referrer Policy: no-referrer-when-downgrade
  
  Response Headers :
  Cache-Control: no-store, no-cache, must-revalidate
  Cache-Control: post-check=0, pre-check=0
  Content-Disposition: attachment; filename="[website.net].t2508126.torrent"
  Content-Length: 33641
  Content-Type: application/x-bittorrent; name="[website.net].t2508126.torrent"
  Date: Thu, 14 Feb 2019 07:57:08 GMT
  Expires: Mon, 26 Jul 1997 05:00:00 GMT
  Last-Modified: Thu, 14 Feb 2019 07:57:09 GMT
  Pragma: no-cache
  Server: nginx
  Set-Cookie: bb_dl=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/forum/; domain=.website.net
  
  Request Headers :
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9
  Connection: keep-alive
  Cookie: bb_t=a%3A3%3A%7Bi%3A2507902%3Bi%3A1550052944%3Bi%3A2508011%3Bi%3A1550120230%3Bi%3A2508126%3Bi%3A1550125516%3B%7D; bb_data=1-27969311-wXVPJGcedLE1I2mM9H0u-3106784170-1550128652-1550131012-3061288864-1; bb_dl=2508126
  Host: website.net
  Referer: https://website.net/forum/viewtopic.php?t=2508126
  Upgrade-Insecure-Requests: 1
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3701.0 Safari/537.36
  
  Query String Parameters :
  t: 2508126
  </code></pre>
  
  <p>Response when opening the download link on it's own (doesn't work) :</p>
  
  <pre><code>General :
  Request URL: https://website.net/forum/dl.php?t=2508126
  Request Method: GET
  Status Code: 200 OK
  Remote Address: 185.37.128.136:443
  Referrer Policy: no-referrer-when-downgrade
  
  Response Headers :
  Cache-Control: no-store, no-cache, must-revalidate
  Cache-Control: post-check=0, pre-check=0
  Content-Type: text/html; charset=windows-1251
  Date: Thu, 14 Feb 2019 08:03:29 GMT
  Expires: Mon, 26 Jul 1997 05:00:00 GMT
  Last-Modified: Thu, 14 Feb 2019 08:03:29 GMT
  Pragma: no-cache
  Server: nginx
  Transfer-Encoding: chunked
  
  Request Headers :
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9
  Connection: keep-alive
  Cookie: bb_t=a%3A3%3A%7Bi%3A2507902%3Bi%3A1550052944%3Bi%3A2508011%3Bi%3A1550120230%3Bi%3A2508126%3Bi%3A1550125516%3B%7D; bb_data=1-27969311-wXVPJGcedLE1I2mM9H0u-3106784170-1550128652-1550131390-3061288864-1
  Host: website.net
  Upgrade-Insecure-Requests: 1
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3701.0 Safari/537.36
  
  Query String Parameters :
  t: 2508126
  </code></pre>