0
我正在尝试使用以下代码从网址中读取文本,以便将所有有效的字符串存储到一个我可以稍后操作的变量中。我在运行时得到一个错误,虽然BeautifulSoup getText抛出一个错误
from bs4 import BeautifulSoup
import urllib.request
from django.template.defaultfilters import title
response = urllib.request.urlopen('http://www.scotland.org/about-scotland/facts-about-scotland/')
data = response.read()
soup = BeautifulSoup(data)
textString = soup.findAll('p').getText()
print(textString)
错误:
textString = soup.findAll('p').getText()
AttributeError: 'ResultSet' object has no attribute 'getText'
啊这个工程,虽然只需要从第一段的数据 – algorhythm
@CMac检查我的编辑。 –