如何解决BeautifulSoup分解元素的多个类
我想删除某些span元素,总共约10个单独的类。我可以重复10次代码来完成乏味的工作,但这不是正确的学习方法。
这就是我要简化的工作:
for span in table_tag.find_all("span",{'class':'class1'}):
span.decompose()
for span in table_tag.find_all("span",{'class':'class2'}):
span.decompose()
for span in table_tag.find_all("span",{'class':'class3'}):
span.decompose()
这是我尝试过的,但没有删除任何东西:
remove = table_tag.find_all('class1','class2','class3')
for span in table_tag.find_all("span",{'class': remove}):
span.decompose()
BeautifulSoup文档对如何在一个命令中分解多个元素并没有帮助我。同样,当我在find_all命令中超过5个类时,我得到一个错误,即find_all接受1到6个位置参数,但给出了7个。显然我使用的命令错误,请只需要一些帮助。
谢谢。
解决方法
classes = ['class1','class2'....]
for i in classes:
for span in table_tag.find_all("span",{'class': i}):
span.decompose()
,
您可以将CSS选择器与逗号//ViewController.swift
class ViewController: UIViewController {
var latitude : Float = 0.0
SendGeocodeRequest(query: query_origin) { ltd in
self.latitude = ltd
}
}
一起使用:
,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。