title: Bash Python Library Function - Using Beautiful Soup in shell for HTML-plaintext
body: <p>I'm trying to use a bash script in venv to convert a bunch of HTML files in a given directory to plaintext.</p>
  
  <p>Example: <strong>file1.html, file2.html</strong> -> <strong>file1.txt, file2.txt</strong>, where each .txt file is the plaintext from the respective HTML files.</p>
  
  <p>I'm using the Beautiful Soup library (specifically, the <strong>get_text()</strong> function), but am having trouble wrapping my head around how exactly to call the function on each .html file.</p>
  
  <p>The following is what I've been using so far:</p>
  
  <pre><code>for i in *; do python -c 'import bs4; print(bs4.BeautifulSoup("'$i'").get_text())' &gt; "$i".txt; done
  </code></pre>
  
  <p>... where $i refers to the current file in the directory as I am iterating one by one. </p>
  
  <p>This currently writes just the filename into the .txt file instead of the Beautiful Soup'd HTML code-into-plaintext:</p>
  
  <pre><code>$ cat file.txt
  poop.html
  </code></pre>
  
  <p>It also yields the following warning: <em>"file.html" looks like a filename, not markup. You should probably open this file and pass the filehandle into Beautiful Soup.</em></p>
  
  <p>Can anyone lend a hand? Thanks in advance for any help.</p>