真正基本的问题:
怎么会。我从:
返回001,002 ... 101<us-applicant sequence="001" app-type="applicant" designation="us-only">
...
<us-applicant sequence="101" app-type="applicant" designation="us-only">
用美味的汤?我知道在两个标签之间返回内容的基本外观,但我不确定这个元素到底是什么
答案 0 :(得分:1)
你可以做这样的事情,使用列表理解,你使用['sequence']
得到属性:
from bs4 import BeautifulSoup
data = '''
<us-applicant sequence="001" app-type="applicant" designation="us-only">
<us-applicant sequence="100" app-type="applicant" designation="us-only">
<us-applicant sequence="101" app-type="applicant" designation="us-only">
'''
soup = BeautifulSoup(data, 'html.parser')
>>> [tag['sequence'] for tag in soup.findAll('us-applicant')]
['001', '100', '101']