Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 're' is not defined [duplicate]

Tags:

I am very new to python. Very new. I copied the following from a tutorial

#!/usr/bin/python  from urllib import urlopen from BeautifulSoup import BeautifulSoup  webpage = urlopen('http://feeds.huffingtonpost.com/huffingtonpost/LatestNews').read  patFinderTitle = re.compile('<title>(.*)</title>')  patFinderLink = re.compile('<link rel.*href="(.*)"/>')  findPatTitle = re.findall(patFinderTitle,webpage)  findPatLink = re.findall(patFinderLink,webpage)  listIterator = [] listIterator[:] = range(2,16)  for i in listIterator:     print findPatTitle[i]     print findPatLink[i]     print "\n" 

I get the error:

Traceback (most recent call last):   File "test.py", line 8, in <module>     patFinderTitle = re.compile('<title>(.*)</title>') NameError: name 're' is not defined 

What am I doing wrong?

like image 647
user_78361084 Avatar asked Sep 19 '11 01:09

user_78361084


1 Answers

You need to import regular expression module in your code

import re re.compile('<title>(.*)</title>') 
like image 102
TheOneTeam Avatar answered Sep 28 '22 04:09

TheOneTeam