title: Using bs4 to extract text in html files
body: <p>Want to extract text from my html files. if I use below for a specific file:</p>
  
  <pre><code>import bs4, sys
  from urllib import urlopen
  #filin = open(sys.argv[1], 'r')
  filin = '/home/iykeln/Desktop/R_work/file1.html' 
  webpage = urlopen(filin).read().decode('utf-8')
  soup = bs4.BeautifulSoup(webpage)
  for node in soup.findAll('html'):
      print u''.join(node.findAll(text=True)).encode('utf-8')
  </code></pre>
  
  <p>it will work.
  But trying below for non specific files using open(sys.argv[1], 'r'):</p>
  
  <pre><code>import bs4, sys
  from urllib import urlopen
  filin = open(sys.argv[1], 'r')
  #filin = '/home/iykeln/Desktop/R_work/file1.html' 
  webpage = urlopen(filin).read().decode('utf-8')
  soup = bs4.BeautifulSoup(webpage)
  for node in soup.findAll('html'):
      print u''.join(node.findAll(text=True)).encode('utf-8')
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>import bs4, sys
  from urllib import urlopen
  with open(sys.argv[1], 'r') as filin:
      webpage = urlopen(filin).read().decode('utf-8')
      soup = bs4.BeautifulSoup(webpage)
      for node in soup.findAll('html'):
          print u''.join(node.findAll(text=True)).encode('utf-8')
  </code></pre>
  
  <p>I will be getting errors below:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/iykeln/Desktop/py/clean.py", line 5, in &lt;module&gt;
      webpage = urlopen(filin).read().decode('utf-8')
    File "/usr/lib/python2.7/urllib.py", line 87, in urlopen
      return opener.open(url)
    File "/usr/lib/python2.7/urllib.py", line 180, in open
      fullurl = unwrap(toBytes(fullurl))
    File "/usr/lib/python2.7/urllib.py", line 1057, in unwrap
      url = url.strip()
  AttributeError: 'file' object has no attribute 'strip'
  </code></pre>