Home > Back-end >  How to find particular data from an html using range of index in python list while scraping data wit
How to find particular data from an html using range of index in python list while scraping data wit

Time:10-15

from bs4 import BeautifulSoup as Soup
import json


b = '''
<section class="warr-section is-expand" id="upgradeWarranty"><span class="show-differences differences-button notDisplay"></span><span class="hide-differences differences-button notDisplay"></span><div class="stackableSection stackable-selected" groupcode="Depot Warranty" priority="2"><div class="sectionContent sectionContentDisplay"><div class="merchContainer hasImg upgrande-warranty-merchcontainer" style="height: 517px;"><div class="merchExpandArrow"><i class="fa fa-angle-down fa-2x merch-expand-arrow" isexpand="true"></i></div><div class="merchImg"><img src="/medias/depot.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDIzMTB8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGYyL2gzMi8xMDU0OTkxMzcxNDcxOC5wbmd8ZTIwNGYwMjQxZTY1YjIzNjRmNGRlZDFmZTgzMmY2YTgwYThhZGNjZDg2MGFhMWFjYzkzZjU3MjAyNzMzZGZmNw" style="height: 55px;"></div><div class="stackableHeader stackabel-header-pos upgrade-warranty-stackable-header" style="height: 64px;"><span class="merchImg-for-mobile notDisplay"><img src="/medias/depot.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDIzMTB8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGYyL2gzMi8xMDU0OTkxMzcxNDcxOC5wbmd8ZTIwNGYwMjQxZTY1YjIzNjRmNGRlZDFmZTgzMmY2YTgwYThhZGNjZDg2MGFhMWFjYzkzZjU3MjAyNzMzZGZmNw"></span><span class="good-tag-for-mobile notDisplay">GOOD</span><span class="pos_group_title">Depot Support</span><span class="pos_group_info_icon" attr-code="Depot Warranty"><img src="/_ui/desktop/common/css/images/pos_group_icon.png"></span><span class="startAt-for-mobile notDisplay">One Year</span><span class="expand-icon-for-mobile notDisplay fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-up fa-stack-1x"></i></span></div><div class="good-better-best-tag hastag selected-group" style="height: 44px;"><span class="good-better-best-text">GOOD</span></div><div class="merchText select-warranty-merchtext"><p style="height: 40px;" class="InsidecontentText" row-index="0"><span><i class="fa fa-check"> </i></span><span>Parts &amp; Labor</span></p> <p class="InsidecontentText" row-index="1" style="height: 57px;"><span><i class="fa fa-check"> </i></span><span>Basic Phone Support for hardware issues</span></p> <p class="InsidecontentText" row-index="2" style="height: 77px;"><span><i class="fa fa-check"> </i></span><span>Repairs done with shipment to Lenovo Depot (<b>shipping costs covered by Lenovo</b>)</span></p></div></div><div class="partContainer part-container-pos"><ul><li class="starting-at-option" group-minprice="0"><label style="height: 0px;"><span style="text-align:left">One Year</span><span style="text-align:right"><i class="fa fa-pencil"></i></span></label></li></ul><ul><li class="stackableWarranty-optionList-option option_1471572303 selected warranty-option" optionid="option_1471572303" value="" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76367&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48376&quot;]}" group-id="Depot Warranty" option-index="optionIndex_0" isbasewarranty="true"><input type="hidden" id="option_1471572303" name="options_11" value=""><label><div class="btnText" style="height: 55px;"><span>Base Warranty</span><span class="warrantyYear">One Year</span><i class="fa fa-check"></i></div></label></li><li class="stackableWarranty-optionList-option option_1754247872 warranty-option" optionid="option_1754247872" value="5WS0K76348" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76361&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48380&quot;]}" group-id="Depot Warranty" option-index="optionIndex_1" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Two Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 79-0">  $79.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_234087166 warranty-option" optionid="option_234087166" value="5WS0K76347" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76365&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48373&quot;]}" group-id="Depot Warranty" option-index="optionIndex_2" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Three Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 105-0">  $105.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_1407905887 warranty-option" optionid="option_1407905887" value="5WS0M73802" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0W36590&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W36585&quot;]}" group-id="Depot Warranty" option-index="optionIndex_3" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Four year</span></div><div class="option_price_items"><span class="stackablePriceLabel 129-0">  $129.00</span></div></div></label></li></ul></div></div></div><div class="stackableSection" groupcode="Onsite Warranty NBD" priority="3"><div class="sectionContent sectionContentDisplay"><div class="merchContainer hasImg upgrande-warranty-merchcontainer" style="height: 517px;"><div class="merchExpandArrow"><i class="fa fa-angle-down fa-2x merch-expand-arrow" isexpand="true"></i></div><div class="merchImg"><img src="/medias/onsite.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDIyNDl8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGZiL2gxNi8xMDU0OTkxNDA0MjM5OC5wbmd8MGM0MjZlZTA4MDY0NWZlZGE5OTY4NDA3OGJiYjVhZjFlMTBhZDM0MmU4Y2MwZDMzMzA1NzQ1MzAxZGJhYWZmYg" style="height: 55px;"></div><div class="stackableHeader stackabel-header-pos upgrade-warranty-stackable-header" style="height: 64px;"><span class="merchImg-for-mobile notDisplay"><img src="/medias/onsite.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDIyNDl8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGZiL2gxNi8xMDU0OTkxNDA0MjM5OC5wbmd8MGM0MjZlZTA4MDY0NWZlZGE5OTY4NDA3OGJiYjVhZjFlMTBhZDM0MmU4Y2MwZDMzMzA1NzQ1MzAxZGJhYWZmYg"></span><span class="good-tag-for-mobile notDisplay">BETTER</span><span class="pos_group_title">Onsite Support</span><span class="pos_group_info_icon" attr-code="Onsite Warranty NBD"><img src="/_ui/desktop/common/css/images/pos_group_icon.png"></span><span class="startAt-for-mobile notDisplay">Starting at  $50.00</span><span class="expand-icon-for-mobile notDisplay fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-up fa-stack-1x"></i></span></div><div class="good-better-best-tag hastag" style="height: 44px;"><span class="good-better-best-text">BETTER</span></div><div class="merchText select-warranty-merchtext"><p style="height: 40px;" class="InsidecontentText" row-index="0"><span><i class="fa fa-check"> </i></span><span>Parts &amp; Labor</span></p> <p class="InsidecontentText" row-index="1" style="height: 57px;"><span><i class="fa fa-check"> </i></span><span>Basic Phone Support for hardware issues</span></p> <p class="InsidecontentText" row-index="2" style="height: 77px;"><span><i class="fa fa-check"> </i></span><span><b>Faster</b> - Repairs done <b>at your location</b></span></p></div></div><div class="partContainer part-container-pos"><ul><li class="starting-at-option" group-minprice="50.00"><label style="height: 0px;"><span>Starting at  $50.00</span></label></li></ul><ul><li class="stackableWarranty-optionList-option option_1474912093 warranty-option" optionid="option_1474912093" value="5WS0K76362" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76367&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48376&quot;]}" group-id="Onsite Warranty NBD" option-index="optionIndex_0" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">One Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 50-0">  $50.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_327536232 warranty-option" optionid="option_327536232" value="5WS0K76349" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76361&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48380&quot;]}" group-id="Onsite Warranty NBD" option-index="optionIndex_1" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Two Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 89-0">  $89.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_447005205 warranty-option" optionid="option_447005205" value="5WS0K76356" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76365&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48373&quot;]}" group-id="Onsite Warranty NBD" option-index="optionIndex_2" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Three Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 129-0">  $129.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_1952971851 warranty-option" optionid="option_1952971851" value="5WS0W36587" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0W36590&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W36585&quot;]}" group-id="Onsite Warranty NBD" option-index="optionIndex_3" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Four year</span></div><div class="option_price_items"><span class="stackablePriceLabel 169-0">  $169.00</span></div></div></label></li></ul></div></div></div><div class="stackableSection" groupcode="Premium Care" priority="4"><div class="sectionContent sectionContentDisplay"><div class="pd-logodiv"><div class="pd-merch-tagLabel-ribbon" style="background: green;">RECOMMENDED<i class="pd-merch-arrow" style="border-bottom-color: rgb(0, 128, 0); border-top-color: rgb(0, 128, 0);"></i></div></div><div class="merchContainer hasImg upgrande-warranty-merchcontainer" style="height: 517px;"><div class="merchExpandArrow"><i class="fa fa-angle-down fa-2x merch-expand-arrow" isexpand="true"></i></div><div class="merchImg"><img src="/medias/premium-care.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDI0NjN8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGVmL2g2Yy8xMDU1MzYxOTQxNTA3MC5wbmd8OTk2ODlkYzE0YjdlNDQwODcwMWM2OTg4N2E3OTM5NGE4YjAwODBjYWM5YmZlOWJhMzEzYzkxMzUzYTE5NjZkOQ" style="height: 55px;"></div><div class="stackableHeader stackabel-header-pos upgrade-warranty-stackable-header" style="height: 64px;"><span class="merchImg-for-mobile notDisplay"><img src="/medias/premium-care.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDI0NjN8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGVmL2g2Yy8xMDU1MzYxOTQxNTA3MC5wbmd8OTk2ODlkYzE0YjdlNDQwODcwMWM2OTg4N2E3OTM5NGE4YjAwODBjYWM5YmZlOWJhMzEzYzkxMzUzYTE5NjZkOQ"></span><span class="good-tag-for-mobile notDisplay">BEST</span><span class="pos_group_title">Premium Care Onsite Support</span><span class="pos_group_info_icon" attr-code="Premium Care"><img src="/_ui/desktop/common/css/images/pos_group_icon.png"></span><span class="startAt-for-mobile notDisplay">Starting at  $59.00</span><span class="expand-icon-for-mobile notDisplay fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-up fa-stack-1x"></i></span></div><div class="good-better-best-tag hastag" style="height: 44px;"><span class="good-better-best-text">BEST</span></div><div class="merchText select-warranty-merchtext"><p class="InsidecontentText" row-index="0" style="height: 40px;"><span><i class="fa fa-check"> </i></span><span>Parts &amp; Labor</span></p> <p class="InsidecontentText" row-index="1" style="height: 57px;"><span><i class="fa fa-check"> </i></span><span><b>Advanced</b> Phone Support with <b>Dedicated Lenovo Experts</b></span></p> <p class="InsidecontentText" row-index="2" style="height: 77px;"><span><i class="fa fa-check"> </i></span><span><b>Fastest</b> - Repairs done at your location, <b>Next Business Day</b></span></p> <p class="InsidecontentText" row-index="3" style="height: 56px;"><span><i class="fa fa-check"> </i></span><span><b>Comprehensive</b> Hardware &amp; <b>Software Support</b></span></p> <p class="InsidecontentText" row-index="4" style="height: 56px;"><span><i class="fa fa-check"> </i></span><span><b>Getting Started &amp; "How To" Assistance</b></span></p> <p class="InsidecontentText" row-index="5" style="height: 56px;"><span><i class="fa fa-check"> </i></span><span><b>Comprehensive Yearly Health Check</b></span></p></div></div><div class="partContainer part-container-pos"><ul><li class="starting-at-option" group-minprice="59.00"><label style="height: 0px;"><span>Starting at  $59.00</span></label></li></ul><ul><li class="stackableWarranty-optionList-option option_1225403106 warranty-option" optionid="option_1225403106" value="5WS0T73712" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76367&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48376&quot;]}" group-id="Premium Care" option-index="optionIndex_0" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">One Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 59-0">  $59.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_758229783 warranty-option" optionid="option_758229783" value="5WS0T73710" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76361&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48380&quot;]}" group-id="Premium Care" option-index="optionIndex_1" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Two Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 105-0">  $105.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_830081606 warranty-option" optionid="option_830081606" value="5WS0T73708" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76365&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48373&quot;]}" group-id="Premium Care" option-index="optionIndex_2" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Three Year</span></div><div class="option_price_items"><span class="strike_through">  $159.00</span><span class="stackablePriceLabel">  $127.00</span><span class="saving_price">Savings Of $32.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_359776740 warranty-option" optionid="option_359776740" value="5WS0W36573" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0W36590&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W36585&quot;]}" group-id="Premium Care" option-index="optionIndex_3" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Four year</span></div><div class="option_price_items"><span class="strike_through">  $209.00</span><span class="stackablePriceLabel">  $167.00</span><span class="saving_price">Savings Of $42.00</span></div></div></label></li></ul></div></div></div><div class="choose-option-container"><a class="choose-option"><span class="fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-down fa-stack-1x"></i></span></a><a class="hide-option"><span class="fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-up fa-stack-1x"></i></span></a></div></section>
'''

new_soup = Soup(b, 'html.parser')

#print(new_soup.prettify())


d = new_soup.find_all('li')
for b in range(len(d)):
    e = d[b]
    print(e)

Now when I run the code it gives me all the 15 list.

d = new_soup.find_all('li')
e = d[2]
c = e['optionid']
print(c.strip('option_'))

I get output as '1754247872'

What I want is some logic e = d[1:15] so the I can get all the option id 1 by one if present.

I even tried Beautifulsoup method

new_soup = Soup(b, 'html.parser')
d = new_soup.find_all('li')
e = d.find('optionid')
print(e)

I get the error as "AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()? "

All I want is to fetch the option id code from the list tag, But don't know how should I do that with BeautifulSoup, or Selenium.

Also for 1st example, I was trying to fetch option id, Because every list tag has same class name, just option tag is different. So I would 1st get all the option id first, then by using f string I can append it using for loop 1 by one to fetch data.

I don't know what I'm doing is right or wrong, But let's hope for the Best.

CodePudding user response:

try :

...

for li in new_soup.find_all("li"):
    for attr in li.attrs.get('class', []):

        if attr.startswith('option_'):
            print(attr.split("_")[-1])


1471572303
1754247872
234087166
1407905887
1474912093
327536232
447005205
1952971851
1225403106
758229783
830081606
359776740

CodePudding user response:

What happens?

As mentioned d is a list and this has no attribut find().

How to fix?

Select all <li> that have an attribut optionid and iterate over it to print:

for li in new_soup.select('li[optionid]'):
    print(li['optionid'].split('_')[-1])

or generate a list with the values:

[li['optionid'].split('_')[-1] for li in new_soup.select('li[optionid]')]

Example

from bs4 import BeautifulSoup as Soup
import json


b = '''
<section class="warr-section is-expand" id="upgradeWarranty"><span class="show-differences differences-button notDisplay"></span><span class="hide-differences differences-button notDisplay"></span><div class="stackableSection stackable-selected" groupcode="Depot Warranty" priority="2"><div class="sectionContent sectionContentDisplay"><div class="merchContainer hasImg upgrande-warranty-merchcontainer" style="height: 517px;"><div class="merchExpandArrow"><i class="fa fa-angle-down fa-2x merch-expand-arrow" isexpand="true"></i></div><div class="merchImg"><img src="/medias/depot.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDIzMTB8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGYyL2gzMi8xMDU0OTkxMzcxNDcxOC5wbmd8ZTIwNGYwMjQxZTY1YjIzNjRmNGRlZDFmZTgzMmY2YTgwYThhZGNjZDg2MGFhMWFjYzkzZjU3MjAyNzMzZGZmNw" style="height: 55px;"></div><div class="stackableHeader stackabel-header-pos upgrade-warranty-stackable-header" style="height: 64px;"><span class="merchImg-for-mobile notDisplay"><img src="/medias/depot.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDIzMTB8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGYyL2gzMi8xMDU0OTkxMzcxNDcxOC5wbmd8ZTIwNGYwMjQxZTY1YjIzNjRmNGRlZDFmZTgzMmY2YTgwYThhZGNjZDg2MGFhMWFjYzkzZjU3MjAyNzMzZGZmNw"></span><span class="good-tag-for-mobile notDisplay">GOOD</span><span class="pos_group_title">Depot Support</span><span class="pos_group_info_icon" attr-code="Depot Warranty"><img src="/_ui/desktop/common/css/images/pos_group_icon.png"></span><span class="startAt-for-mobile notDisplay">One Year</span><span class="expand-icon-for-mobile notDisplay fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-up fa-stack-1x"></i></span></div><div class="good-better-best-tag hastag selected-group" style="height: 44px;"><span class="good-better-best-text">GOOD</span></div><div class="merchText select-warranty-merchtext"><p style="height: 40px;" class="InsidecontentText" row-index="0"><span><i class="fa fa-check"> </i></span><span>Parts &amp; Labor</span></p> <p class="InsidecontentText" row-index="1" style="height: 57px;"><span><i class="fa fa-check"> </i></span><span>Basic Phone Support for hardware issues</span></p> <p class="InsidecontentText" row-index="2" style="height: 77px;"><span><i class="fa fa-check"> </i></span><span>Repairs done with shipment to Lenovo Depot (<b>shipping costs covered by Lenovo</b>)</span></p></div></div><div class="partContainer part-container-pos"><ul><li class="starting-at-option" group-minprice="0"><label style="height: 0px;"><span style="text-align:left">One Year</span><span style="text-align:right"><i class="fa fa-pencil"></i></span></label></li></ul><ul><li class="stackableWarranty-optionList-option option_1471572303 selected warranty-option" optionid="option_1471572303" value="" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76367&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48376&quot;]}" group-id="Depot Warranty" option-index="optionIndex_0" isbasewarranty="true"><input type="hidden" id="option_1471572303" name="options_11" value=""><label><div class="btnText" style="height: 55px;"><span>Base Warranty</span><span class="warrantyYear">One Year</span><i class="fa fa-check"></i></div></label></li><li class="stackableWarranty-optionList-option option_1754247872 warranty-option" optionid="option_1754247872" value="5WS0K76348" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76361&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48380&quot;]}" group-id="Depot Warranty" option-index="optionIndex_1" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Two Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 79-0">  $79.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_234087166 warranty-option" optionid="option_234087166" value="5WS0K76347" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76365&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48373&quot;]}" group-id="Depot Warranty" option-index="optionIndex_2" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Three Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 105-0">  $105.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_1407905887 warranty-option" optionid="option_1407905887" value="5WS0M73802" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0W36590&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W36585&quot;]}" group-id="Depot Warranty" option-index="optionIndex_3" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Four year</span></div><div class="option_price_items"><span class="stackablePriceLabel 129-0">  $129.00</span></div></div></label></li></ul></div></div></div><div class="stackableSection" groupcode="Onsite Warranty NBD" priority="3"><div class="sectionContent sectionContentDisplay"><div class="merchContainer hasImg upgrande-warranty-merchcontainer" style="height: 517px;"><div class="merchExpandArrow"><i class="fa fa-angle-down fa-2x merch-expand-arrow" isexpand="true"></i></div><div class="merchImg"><img src="/medias/onsite.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDIyNDl8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGZiL2gxNi8xMDU0OTkxNDA0MjM5OC5wbmd8MGM0MjZlZTA4MDY0NWZlZGE5OTY4NDA3OGJiYjVhZjFlMTBhZDM0MmU4Y2MwZDMzMzA1NzQ1MzAxZGJhYWZmYg" style="height: 55px;"></div><div class="stackableHeader stackabel-header-pos upgrade-warranty-stackable-header" style="height: 64px;"><span class="merchImg-for-mobile notDisplay"><img src="/medias/onsite.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDIyNDl8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGZiL2gxNi8xMDU0OTkxNDA0MjM5OC5wbmd8MGM0MjZlZTA4MDY0NWZlZGE5OTY4NDA3OGJiYjVhZjFlMTBhZDM0MmU4Y2MwZDMzMzA1NzQ1MzAxZGJhYWZmYg"></span><span class="good-tag-for-mobile notDisplay">BETTER</span><span class="pos_group_title">Onsite Support</span><span class="pos_group_info_icon" attr-code="Onsite Warranty NBD"><img src="/_ui/desktop/common/css/images/pos_group_icon.png"></span><span class="startAt-for-mobile notDisplay">Starting at  $50.00</span><span class="expand-icon-for-mobile notDisplay fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-up fa-stack-1x"></i></span></div><div class="good-better-best-tag hastag" style="height: 44px;"><span class="good-better-best-text">BETTER</span></div><div class="merchText select-warranty-merchtext"><p style="height: 40px;" class="InsidecontentText" row-index="0"><span><i class="fa fa-check"> </i></span><span>Parts &amp; Labor</span></p> <p class="InsidecontentText" row-index="1" style="height: 57px;"><span><i class="fa fa-check"> </i></span><span>Basic Phone Support for hardware issues</span></p> <p class="InsidecontentText" row-index="2" style="height: 77px;"><span><i class="fa fa-check"> </i></span><span><b>Faster</b> - Repairs done <b>at your location</b></span></p></div></div><div class="partContainer part-container-pos"><ul><li class="starting-at-option" group-minprice="50.00"><label style="height: 0px;"><span>Starting at  $50.00</span></label></li></ul><ul><li class="stackableWarranty-optionList-option option_1474912093 warranty-option" optionid="option_1474912093" value="5WS0K76362" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76367&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48376&quot;]}" group-id="Onsite Warranty NBD" option-index="optionIndex_0" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">One Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 50-0">  $50.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_327536232 warranty-option" optionid="option_327536232" value="5WS0K76349" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76361&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48380&quot;]}" group-id="Onsite Warranty NBD" option-index="optionIndex_1" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Two Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 89-0">  $89.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_447005205 warranty-option" optionid="option_447005205" value="5WS0K76356" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76365&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48373&quot;]}" group-id="Onsite Warranty NBD" option-index="optionIndex_2" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Three Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 129-0">  $129.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_1952971851 warranty-option" optionid="option_1952971851" value="5WS0W36587" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0W36590&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W36585&quot;]}" group-id="Onsite Warranty NBD" option-index="optionIndex_3" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Four year</span></div><div class="option_price_items"><span class="stackablePriceLabel 169-0">  $169.00</span></div></div></label></li></ul></div></div></div><div class="stackableSection" groupcode="Premium Care" priority="4"><div class="sectionContent sectionContentDisplay"><div class="pd-logodiv"><div class="pd-merch-tagLabel-ribbon" style="background: green;">RECOMMENDED<i class="pd-merch-arrow" style="border-bottom-color: rgb(0, 128, 0); border-top-color: rgb(0, 128, 0);"></i></div></div><div class="merchContainer hasImg upgrande-warranty-merchcontainer" style="height: 517px;"><div class="merchExpandArrow"><i class="fa fa-angle-down fa-2x merch-expand-arrow" isexpand="true"></i></div><div class="merchImg"><img src="/medias/premium-care.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDI0NjN8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGVmL2g2Yy8xMDU1MzYxOTQxNTA3MC5wbmd8OTk2ODlkYzE0YjdlNDQwODcwMWM2OTg4N2E3OTM5NGE4YjAwODBjYWM5YmZlOWJhMzEzYzkxMzUzYTE5NjZkOQ" style="height: 55px;"></div><div class="stackableHeader stackabel-header-pos upgrade-warranty-stackable-header" style="height: 64px;"><span class="merchImg-for-mobile notDisplay"><img src="/medias/premium-care.png?context=bWFzdGVyfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvfDI0NjN8aW1hZ2UvcG5nfC93dy9pY29ucy9pbnRlcnN0aXRpYWwvc2VydmljZXMvaGVmL2g2Yy8xMDU1MzYxOTQxNTA3MC5wbmd8OTk2ODlkYzE0YjdlNDQwODcwMWM2OTg4N2E3OTM5NGE4YjAwODBjYWM5YmZlOWJhMzEzYzkxMzUzYTE5NjZkOQ"></span><span class="good-tag-for-mobile notDisplay">BEST</span><span class="pos_group_title">Premium Care Onsite Support</span><span class="pos_group_info_icon" attr-code="Premium Care"><img src="/_ui/desktop/common/css/images/pos_group_icon.png"></span><span class="startAt-for-mobile notDisplay">Starting at  $59.00</span><span class="expand-icon-for-mobile notDisplay fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-up fa-stack-1x"></i></span></div><div class="good-better-best-tag hastag" style="height: 44px;"><span class="good-better-best-text">BEST</span></div><div class="merchText select-warranty-merchtext"><p class="InsidecontentText" row-index="0" style="height: 40px;"><span><i class="fa fa-check"> </i></span><span>Parts &amp; Labor</span></p> <p class="InsidecontentText" row-index="1" style="height: 57px;"><span><i class="fa fa-check"> </i></span><span><b>Advanced</b> Phone Support with <b>Dedicated Lenovo Experts</b></span></p> <p class="InsidecontentText" row-index="2" style="height: 77px;"><span><i class="fa fa-check"> </i></span><span><b>Fastest</b> - Repairs done at your location, <b>Next Business Day</b></span></p> <p class="InsidecontentText" row-index="3" style="height: 56px;"><span><i class="fa fa-check"> </i></span><span><b>Comprehensive</b> Hardware &amp; <b>Software Support</b></span></p> <p class="InsidecontentText" row-index="4" style="height: 56px;"><span><i class="fa fa-check"> </i></span><span><b>Getting Started &amp; "How To" Assistance</b></span></p> <p class="InsidecontentText" row-index="5" style="height: 56px;"><span><i class="fa fa-check"> </i></span><span><b>Comprehensive Yearly Health Check</b></span></p></div></div><div class="partContainer part-container-pos"><ul><li class="starting-at-option" group-minprice="59.00"><label style="height: 0px;"><span>Starting at  $59.00</span></label></li></ul><ul><li class="stackableWarranty-optionList-option option_1225403106 warranty-option" optionid="option_1225403106" value="5WS0T73712" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76367&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48376&quot;]}" group-id="Premium Care" option-index="optionIndex_0" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">One Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 59-0">  $59.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_758229783 warranty-option" optionid="option_758229783" value="5WS0T73710" depends="{&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76361&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48380&quot;]}" group-id="Premium Care" option-index="optionIndex_1" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Two Year</span></div><div class="option_price_items"><span class="stackablePriceLabel 105-0">  $105.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_830081606 warranty-option" optionid="option_830081606" value="5WS0T73708" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0K76365&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W48373&quot;]}" group-id="Premium Care" option-index="optionIndex_2" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Three Year</span></div><div class="option_price_items"><span class="strike_through">  $159.00</span><span class="stackablePriceLabel">  $127.00</span><span class="saving_price">Savings Of $32.00</span></div></div></label></li><li class="stackableWarranty-optionList-option option_359776740 warranty-option" optionid="option_359776740" value="5WS0W36573" depends="{&quot;Sealed Battery Replacement&quot;:[&quot;5WS0V98154&quot;],&quot;Accidental Damage Protection&quot;:[&quot;5PS0W36590&quot;],&quot;Keep your Drive&quot;:[&quot;5PS0W36585&quot;]}" group-id="Premium Care" option-index="optionIndex_3" isbasewarranty="false"><label><div class="btnText" style="height: 55px;"><div class="option_price_label"><span></span><span class="warrantyYear">Four year</span></div><div class="option_price_items"><span class="strike_through">  $209.00</span><span class="stackablePriceLabel">  $167.00</span><span class="saving_price">Savings Of $42.00</span></div></div></label></li></ul></div></div></div><div class="choose-option-container"><a class="choose-option"><span class="fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-down fa-stack-1x"></i></span></a><a class="hide-option"><span class="fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-angle-up fa-stack-1x"></i></span></a></div></section>
'''

new_soup = Soup(b, 'html.parser')

for li in new_soup.select('li[optionid]'):
    print(li['optionid'].split('_')[-1])

Output

1471572303
1754247872
234087166
1407905887
1474912093
327536232
447005205
1952971851
1225403106
758229783
830081606
359776740
  • Related