(Python) How to convert my code to python 3 from 2.7
<p>I'm trying to build a basic website crawler, in Python. However, the code that I've gathered from this website <a href="http://null-byte.wonderhowto.com/news/basic-website-crawler-python-12-lines-code-0132785/" rel="nofollow">here</a> is for python 2.7. I'm wondering how I can code this for python 3 or greater. I've began to try and convert it, but I keep running into errors.</p>

<pre><code>import re
import urllib

textfile = open('depth_1.txt', 'wt')
print("Enter the URL you wish to crawl..")
print('Usage  - "http://phocks.org/stumble/creepy/" &lt;-- With the double quotes')
myurl = input("@&gt; ")
for i in re.findall('''href=["'](.[^"']+)["']''', urllib.urlopen(myurl).read(), re.I):
    print(i)
    for ee in re.findall('''href=["'](.[^"']+)["']''', urllib.urlopen(i).read(), re.I):
        print(ee)
        textfile.write(ee+'\n')
textfile.close()
</code></pre>

<h1>Prepare your Python2 code</h1>

<p>Say <code>2.py</code></p>

<pre><code>import re
import urllib

textfile = open('depth_1.txt', 'wt')
print("Enter the URL you wish to crawl..")
print('Usage  - "http://phocks.org/stumble/creepy/" &lt;-- With the double quotes')
myurl = input("@&gt; ")
for i in re.findall('''href=["'](.[^"']+)["']''', urllib.urlopen(myurl).read(), re.I):
    print(i)
    for ee in re.findall('''href=["'](.[^"']+)["']''', urllib.urlopen(i).read(), re.I):
        print(ee)
        textfile.write(ee+'\n')
textfile.close()
</code></pre>

<h1>Convert it with <code>2to3</code></h1>

<pre><code>2to3 -w 2.py
</code></pre>

<h1>Now look into the directory with <code>dir</code> or <code>ls</code></h1>

<pre><code>&gt; dir
2016-09-24  01:53               533 2.py
2016-09-24  01:51               475 2.py.bak
</code></pre>

<p><code>2.py.bak</code> is your original code and <code>2.py</code> is Python 3 code.</p>

<h2>See what changes have been made</h2>

<pre><code>import re
import urllib.request, urllib.parse, urllib.error

textfile = open('depth_1.txt', 'wt')
print("Enter the URL you wish to crawl..")
print('Usage  - "http://phocks.org/stumble/creepy/" &lt;-- With the double quotes')
myurl = eval(input("@&gt; "))
for i in re.findall('''href=["'](.[^"']+)["']''', urllib.request.urlopen(myurl).read(), re.I):
    print(i)
    for ee in re.findall('''href=["'](.[^"']+)["']''', urllib.request.urlopen(i).read(), re.I):
        print(ee)
        textfile.write(ee+'\n')
textfile.close()
</code></pre>

<p><strong>This works if you are using only built-ins and standard modules.</strong> In your case, it's ok.</p>

python python-2.7 python-3.x