I'm trying to create a list of filter facets. I've loaded all the <span>
in to a list with bs4 and now need to grab a specific substring out of the larger string that is the <span>
. I want to load each filter facet name in to a list to end up with a list that looks like this: [size, width, colour, etc]
.
list generated with bs4
[<span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Size" data-v-05f803b1="">Size</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Width" data-v-05f803b1="">Width</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Colour" data-v-05f803b1="">Colour</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Heel Height" data-v-05f803b1="">Heel Height</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Product Type" data-v-05f803b1="">Product Type</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Function" data-v-05f803b1="">Function</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Age" data-v-05f803b1="">Age</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Technology" data-v-05f803b1="">Technology</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Material" data-v-05f803b1="">Material</span>, <span class="col-sm-8 col-xs-9 facet-menu-facet__filter-name-spacing" data-facet-name="Price" data-v-05f803b1="">Price</span>]
what I've tried and doesn't seem to get me anywhere:
facetcode = [str(i) for i in spans]
facets = []
for i in facetcode:
facetcode1 = i.split(' ')
for y in facetcode1:
if 'data-facet-name' == True:
print(y)
when I print(y)
it give me a blank list but I'm expecting something like: data-facet-name="Size"
The result I want:
[size, width, colour, etc]
Am I over complicating this? The idea is to iterate over each list element and load only the text I want in to a new list.