【发布时间】:2018-05-10 04:54:31
【问题描述】:
我正在使用 BeautifulSoup 和 urllib 来制作维基百科网络爬虫。我只是不断收到同样烦人的错误。
我的代码:
from bs4 import BeautifulSoup
import urllib
page = urllib.urlopen("https://en.wikipedia.org/wiki/Donald_Trump").read()
soup = BeautifulSoup(page, "html.parser")
nickname = soup.find_all("span", class_="nickname")
nickname.replace('[<span class="nickname">','')
nickname.replace('</span>]','')
print(nickname)
错误:
AttributeError: 'ResultSet' object has no attribute 'replace'
【问题讨论】:
-
昵称不是字符串
-
@user1767754 这似乎有点帮助。谢谢。
标签: python python-2.7 beautifulsoup urllib