【发布时间】:2013-06-12 13:44:13
【问题描述】:
我是一个新手,在使用 BeautifulSoup 从页面中抓取 html 后无法删除 span 标签。尝试使用“del links['span'] 但它返回了相同的结果。使用 getText() 的一些尝试也失败了。显然我做错了什么应该很容易。帮助?
from bs4 import BeautifulSoup
import urllib.request
import re
url = urllib.request.urlopen("http://www.python.org")
content = url.read()
soup = BeautifulSoup(content)
for links in soup.find_all("span", text=re.compile(".com")):
del links['class']
print(links.)
【问题讨论】:
-
你想做什么?删除 span tags 或删除 span elements(包括它们的内容)
-
@user1929959 问题的答案没有使用 BeautifulSoup。
标签: python python-3.x