Robert Birch
Robert Birch

Reputation: 251

Python Re Beautiful Soup Unexpected String

I am using the following code from this tutorial.

import urllib2
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
import re

webpage = urlopen('http://feeds.huffingtonpost.com/huffingtonpost/LatestNews').read
# open webpage and read it web page is variable

patFinderTitle = re.compile('<title>(.*)</title>')
# get characters between titles

patFinderLink = re.compile('<link rel.*href="(.*)" />')

findPatTitle = re.findall(patFinderTitle, webpage)
# variable is declared, uses re module to find all find two variables using the following args
findPatLink = re.findall(patFinderLink, webpage)

listIterator - []
listIterator[:] = range(2,16)

soup2 = BeautifulSoup(webpage)

print soup2.findAll('title')

However, I get this error.

Traceback (most recent call last):
  File "tutorial_re.py", line 14, in <module>
    findPatTitle = re.findall(patFinderTitle, webpag
  File "C:\Python27\lib\re.py", line 177, in findall
    return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer

I'm using python 2.75. I do not understand this error at all. Why do I have this error? How do I resolve it? Thanks for your help in advance. Some forums say I should give it an 3rd argument but the code seems verbatim to me as it is in the video at around the 9:45 mark.

Upvotes: 0

Views: 96

Answers (1)

manonthemat
manonthemat

Reputation: 6251

what is the output when you actually call read() - with parenthesis - in line 6?

webpage = urlopen('http://feeds.huffingtonpost.com/huffingtonpost/LatestNews').read()

Upvotes: 1

Related Questions