I would like to get all the <script>
tags in a document and then process each one based on the presence (or absence) of certain attributes.
E.g., for each <script>
tag, if the attribute for
is present do something; else if the attribute bar
is present do something else.
Here is what I am doing currently:
outputDoc = BeautifulSoup(''.join(output))
scriptTags = outputDoc.findAll('script', attrs = {'for' : True})
But this way I filter all the <script>
tags with the for
attribute... but I lost the other ones (those without the for
attribute).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…