title: Using urllib3 with python 2.7 to download .txt file from url?
body: <p>I'm using Python 2.7, and I have urllib3.  I'm trying to download each of the .txt files in this link: <a href="http://web.mta.info/developers/turnstile.html" rel="nofollow noreferrer">http://web.mta.info/developers/turnstile.html</a></p>
  
  <p>Here's my code:</p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  from bs4 import BeautifulSoup
  import requests
  import urllib3, shutil
  
  
  http = urllib3.PoolManager()
  
  MTA_url = requests.get("http://web.mta.info/developers/turnstile.html").text
  MTA_soup = BeautifulSoup(MTA_url)
  #Find each link to be downloaded
  MTA_soup.findAll('a')
  #Let's test it with the 36th link
  one_a_tag = MTA_soup.findAll("a")[36]
  MTA_link = one_a_tag["href"]
  
  download_url = 'http://web.mta.info/developers/'+ MTA_link
  print download_url #valid url, will take you to download
  </code></pre>
  
  <p>This is where I'm stuck. I can't seem to figure out how to download the .txt file at <code>download_url</code>, let alone iterate through the list. I've tried this:</p>
  
  <pre><code>open('/Users/me/Documents/test_output_download.csv', 'wb').write(download_url.content)
  </code></pre>
  
  <p>But that gives me the error:</p>
  
  <pre><code>AttributeError: 'unicode' object has no attribute 'content'
  </code></pre>
  
  <p>After reading further, I also tried:</p>
  
  <pre><code>out_file = '/Users/me/Documents/test_output_download.csv'
  http.request('GET', download_url, preload_content=False) as res, open(out_file, 'wb') as out_file:
     shutil.copyfileobj(res, out_file)
  </code></pre>
  
  <p>But I get past this syntax error:</p>
  
  <pre><code>    http.request('GET', download_url, preload_content=False) as res, open(out_file, 'wb') as out_file:
                                                                ^
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>How can I just download the .txt file that is located at <code>download_url</code> and save it to my local drive, using urllib3?  Thank you in advance.</p>