Python: how to get text from html file
<p>I have a folder with some <code>html-file</code> with</p>

<pre><code>import os
indir = 'html/'
for root, dirs, filenames in os.walk(indir):
    for f in filenames:
        page = open(f)
</code></pre>

<p>But it returns me <code>IOError: [Errno 2] No such file or directory: '0out.html'.</code></p>

<p>But there are files <code>0out.html, 1out.html, 2out.html</code>.
I also try <code>codecs</code> but it return this error too.
Where is an error there?</p>

<p>You need to prepend the path to the file.</p>

<pre><code>import os
indir = 'html/'
for root, dirs, filenames in os.walk(indir):
    for f in filenames:
        page = open(os.path.join(indir ,f)) # &lt;-- note the added path
</code></pre>

<p>Without it, you are trying to open a file named <code>0out.html</code> which is a peer to your <code>indir</code>. When you prepend the path, you indicate that it is a child.</p>

python html