问题描述
我想删除某些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
}
}
一起使用:
,