0

このチュートリアルの次のコードを使用しています。

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')

ただし、このエラーが発生します。

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

私はpython 2.75を使用しています。このエラーがまったくわかりません。なぜこのエラーが発生するのですか? どうすれば解決できますか? 事前にご協力いただきありがとうございます。一部のフォーラムでは、3 番目の引数を指定する必要があると言われていますが、ビデオの 9:45 付近にあるコードはそのままのように思えます。

4

1 に答える 1