How can I print a webpage line by line in Python 3.x
<p>All I want to do is print the HTML text of a simple website. When I try printing, I get the text below in raw format with newline characters (<code>\n</code>) instead of actual new lines.</p>

<p><strong>This is my code:</strong></p>

<pre><code>import urllib.request

page = urllib.request.urlopen('http://www.york.ac.uk/teaching/cws/wws/webpage1.html', data = None)
pageText = page.read()
pageLines = page.readlines()
print(pageLines)
print(pageText)
</code></pre>

<p>I've tried all kinds of other stuff and discovered some stuff. When I try to index the <code>pageText</code> variable, even after converting it to a string, it does not find any <code>\n</code> character. If I try copying the raw text myself with the new lines represented as <code>\n</code> and I <code>print()</code> that, it converts the <code>\n</code> characters into actual new lines which is what I want. The problem is that I can't get that result without copying it myself.</p>

<p>To show you what I mean, here are some HTML snippets:</p>

<p><strong>Raw text:</strong></p>

<pre><code>b'&lt;HMTL&gt;\n&lt;HEAD&gt;\n&lt;TITLE&gt;webpage1&lt;/TITLE&gt;\n&lt;/HEAD&gt;\n&lt;BODY BGCOLOR="FFFFFf" LINK="006666" ALINK="8B4513" VLINK="006666"&gt;\n
</code></pre>

<p><strong>What I want:</strong></p>

<pre><code>b'&lt;HMTL&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;webpage1&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY BGCOLOR='FFFFFf' LINK='006666' ALINK='8B4513' VLINK='006666'&gt;
</code></pre>

<p>I also used:</p>

<pre><code>page = str(page)
lines = page.split('\n')
</code></pre>

<p>and it suprisingly did nothing.
It just printed it as one line.</p>

<p>Please, help me. I am surprised that I found nothing that worked for me. Even on forums, nothing worked.</p>

<p>Whet you have is not text but bytes. If you want text just decode it.</p>

<pre><code>b = b'&lt;HMTL&gt;\n&lt;HEAD&gt;\n&lt;TITLE&gt;webpage1&lt;/TITLE&gt;\n&lt;/HEAD&gt;\n&lt;BODY BGCOLOR="FFFFFf" LINK="006666" ALINK="8B4513" VLINK="006666"&gt;\n'
s = b.decode()  # might need to specify an encoding
print(s)
</code></pre>

<p>Output:</p>

<pre><code>&lt;HMTL&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;webpage1&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY BGCOLOR="FFFFFf" LINK="006666" ALINK="8B4513" VLINK="006666"&gt;
</code></pre>

python python-3.x web