Wednesday 15 August 2012

python - BeautifulSoup getText throwing an error -



python - BeautifulSoup getText throwing an error -

i'm trying read text web url using next code store valid strings variable can manipulate later. getting error @ run time though

from bs4 import beautifulsoup import urllib.request django.template.defaultfilters import title response = urllib.request.urlopen('http://www.scotland.org/about-scotland/facts-about-scotland/') info = response.read() soup = beautifulsoup(data) textstring = soup.findall('p').gettext() print(textstring)

error:

textstring = soup.findall('p').gettext() attributeerror: 'resultset' object has no attribute 'gettext'

try this:

textstring = soup.findall('p')[0].gettext()

and if want paragraph info seek this:

elements = soup.findall('p') paragraph in elements: print paragraph.gettext()

python text beautifulsoup gettext

No comments:

Post a Comment