Silkcode
Silkcode

Reputation: 1

I Have this error (NameError: name 'raw_input' is not defined)

My program keeps showing this error raw_input is not defined whenever I use raw_input:

import urllib
from bs4 import BeautifulSoup
url = raw_input('http://py4e-data.dr-chuck.net/known_by_Eqlaas.html: ')
count = int(raw_input("Enter count: "))
position = int(raw_input("Enter position:"))
for i in range(count):
    html = urllib.urlopen(url).read()
    soup = BeautifulSoup(html)

    tags = soup('a')
    s = []
    t = []
    for tag in tags:
        x = tag.get('href', None)
        s.append(x)
        y = tag.text
        t.append(y)

    print (s[position-1])
    print (t[position-1])
    url = s[position-1]

Upvotes: 0

Views: 519

Answers (2)

some_programmer
some_programmer

Reputation: 3568

Since you are using python3, you have to replace

count = int(raw_input("Enter count: "))
position = int(raw_input("Enter position:"))

with

count = int(input("Enter count: "))
position = int(input("Enter position:"))

Upvotes: 1

Roy
Roy

Reputation: 1922

Starting with Python 3, raw_input() was renamed to input().

Upvotes: 4

Related Questions