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?
You need to import regular expression module in your code
import re re.compile('<title>(.*)</title>')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With