Extracting plain text from HTML using Python
<p>I'm trying to extract plain text from a website using python. My code is something like this (a slightly modified version of what I found here):</p>

<pre><code>import requests
import urllib
from bs4 import BeautifulSoup
url = "http://www.thelatinlibrary.com/vergil/aen1.shtml"
r = requests.get(url)
k = r.content
file = open('C:\\Users\\Anirudh\\Desktop\\NEW2.txt','w')
soup = BeautifulSoup(k)
for script in soup(["Script","Style"]):
    script.exctract()
text = soup.get_text
file.write(repr(text))
</code></pre>

<p>This doesn't seem to work. I'm guessing that <code>beautifulsoup</code> doesn't accept <code>r.content</code>. What can I do to fix this?</p>

<p>This is the error  - </p>

<pre><code>UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 8 of the file C:/Users/Anirudh/PycharmProjects/untitled/test/__init__.py. To get rid of this warning, change code that looks like this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html.parser")

  markup_type=markup_type))
Traceback (most recent call last):
  File "C:/Users/Anirudh/PycharmProjects/untitled/test/__init__.py", line 12, in &lt;module&gt;
    file.write(repr(text))
  File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x97' in position 2130: character maps to &lt;undefined&gt;

Process finished with exit code 1
</code></pre>