Estoy usando BeautifulSoup para extraer valores de una lista desordenada pero no soy capaz. Estos son los pasos que hago:
1- Hago un findall a la web buscando los elementos ul con clase "cols"
results = soup.find_all('ul', class_='cols')
2- Me da el siguiente resultado:
[<ul class="cols"> <li value="weapon_knife_survival_bowie">Bowie Knife</li> <li value="weapon_knife_butterfly">Butterfly Knife</li> <li value="weapon_knife_falchion">Falchion Knife</li> <li value="weapon_knife_flip">Flip Knife</li> <li value="weapon_knife_gut">Gut Knife</li> <li value="weapon_knife_tactical">Huntsman Knife</li> <li value="weapon_knife_m9_bayonet">M9 Bayonet</li> <li value="weapon_bayonet">Bayonet</li> <li value="weapon_knife_karambit">Karambit</li> <li value="weapon_knife_push">Shadow Daggers</li> <li value="weapon_knife_stiletto">Stiletto Knife</li> <li value="weapon_knife_ursus">Ursus Knife</li> <li value="weapon_knife_gypsy_jackknife">Navaja Knife</li> <li value="weapon_knife_widowmaker">Talon Knife</li> <li value="weapon_knife_css">Classic Knife</li> <li value="weapon_knife_cord">Paracord Knife</li> <li value="weapon_knife_canis">Survival Knife</li> <li value="weapon_knife_outdoor">Nomad Knife</li> <li value="weapon_knife_skeleton">Skeleton Knife</li> </ul>, <ul class="cols"> <li value="weapon_hkp2000">P2000</li> <li value="weapon_usp_silencer">USP-S</li> <li value="weapon_glock">Glock-18</li> <li value="weapon_p250">P250</li> <li value="weapon_fiveseven">FN57</li> <li value="weapon_cz75a">CZ75-Auto</li> <li value="weapon_tec9">Tec-9</li> <li value="weapon_revolver">R8 Revolver</li> <li value="weapon_deagle">Desert Eagle</li> <li value="weapon_elite">Dual Berettas</li> </ul>, <ul class="cols"> <li value="weapon_galilar">Galil AR</li> <li value="weapon_scar20">SCAR-20</li> <li value="weapon_awp">AWP</li> <li value="weapon_ak47">AK-47</li> <li value="weapon_famas">FAMAS</li> <li value="weapon_m4a1">M4A4</li> <li value="weapon_m4a1_silencer">M4A1-S</li> <li value="weapon_sg556">SG 553</li> <li value="weapon_ssg08">SSG 08</li> <li value="weapon_aug">AUG</li> <li value="weapon_g3sg1">G3SG1</li> </ul>, <ul class="cols"> <li value="weapon_p90">P90</li> <li value="weapon_mac10">MAC-10</li> <li value="weapon_ump45">UMP-45</li> <li value="weapon_mp7">MP7</li> <li value="weapon_bizon">PP-Bizon</li> <li value="weapon_mp9">MP9</li> <li value="weapon_mp5sd">MP5-SD</li> </ul>, <ul class="cols"> <li value="weapon_bloodhound_gloves">Bloodhound Gloves</li> <li value="weapon_driver_gloves">Driver Gloves</li> <li value="weapon_hand_wraps">Hand Wraps</li> <li value="weapon_moto_gloves">Moto Gloves</li> <li value="weapon_specialist_gloves">Specialist Gloves</li> <li value="weapon_sport_gloves">Sport Gloves</li> <li value="weapon_hydra_gloves">Hydra Gloves</li> <li value="weapon_brokenfang_gloves">Broken Fang Glove</li> </ul>, <ul class="cols" style="width:318px;overflow-y:auto;max-height: 385px;padding-bottom: 200px"> <li value="crate_sticker_pack_community2022_capsule">Espionage</li> <li value="sticker_tournament20">Rio 2022</li> <li value="crate_sticker_pack_csgo10_capsule">CSGO 10</li> <li value="sticker_tournament19">Antwerp 2022</li> <li value="crate_sticker_pack_spring2022_capsule">Boardroom</li> <li value="crate_sticker_pack_bf2042_capsule_lootlist">Battlefield 2042</li> <li value="sticker_tournament18">Stockholm 2021</li> <li value="crate_sticker_pack_riptide_surfshop_lootlist">Riptide Surf Shop</li> <li value="crate_sticker_pack_op_riptide_capsule_lootlist">Operation Riptide</li> <li value="sticker_community2021">2021 Community</li> <li value="poorly_drawn">Poorly Drawn</li> <li value="sticker_2020rmr">2020RMR</li> <li value="sticker_broken_fang">Broken Fang</li> <li value="sticker_recoil">Recoil</li> <li value="warhammer_sticker">Warhammer 40K</li> <li value="alyx_sticker_capsule">HL:Alyx</li> <li value="halo_capsule">Halo</li> <li value="shattered_web">Shattered Web</li> <li value="cs20_capsule">CS20</li> <li value="2019_StarLadder_Berlin_Major">Berlin 2019</li> <li value="crate_sticker_pack_chicken_capsule_lootlist">Chicken</li> <li value="crate_sticker_pack_feral_predators_capsule_lootlist">Feral Predators</li> <li value="sticker_tournament15">Katowice 2019</li> <li value="skill_groups_capsule">Skill Group</li> <li value="sticker_tournament14">London 2018</li> <li value="sticker_tournament13">Boston 2018</li> <li value="sticker_tournament12">Krakow 2017</li> <li value="sticker_tournament11">Atlanta 2017</li> <li value="sticker_tournament10">Cologne 2016</li> <li value="sticker_tournament9">Columbus 2016</li> <li value="sticker_tournament8">DreamHack 2015</li> <li value="sticker_tournament7">Cologne 2015</li> <li value="sticker_tournament6">Katowice 2015</li> <li value="sticker_tournament5">DreamHack 2014</li> <li value="sticker_tournament4">Cologne 2014</li> <li value="sticker_tournament3">Katowice 2014</li> <li value="crate_sticker_pack_comm2018_01_capsule_lootlist">Community 2018</li> <li value="crate_sticker_pack01">Sticker 1</li> <li value="crate_sticker_pack02">Sticker 2</li> <li value="crate_sticker_pack_enfu_capsule_lootlist">Enfu Sticker</li> <li value="crate_sticker_pack_illuminate_capsule_01_lootlist">Perfect World 1</li> <li value="crate_sticker_pack_illuminate_capsule_02_lootlist">Perfect World 2</li> <li value="crate_sticker_pack_community01">Community 1</li> <li value="crate_sticker_pack_bestiary_capsule_lootlist">Bestiary</li> <li value="crate_sticker_pack_slid3_capsule_lootlist">Slid3</li> <li value="crate_sticker_pack_sugarface_capsule_lootlist">Sugarface</li> <li value="crate_sticker_pack_pinups_capsule_lootlist">Pinups</li> <li value="crate_sticker_pack_team_roles_capsule_lootlist">Team Roles</li> <li value="sticker_other">Other stickers</li> </ul>, <ul class="cols"> <li value="csgo_type_tool">Tools</li> <li value="csgo_type_spray">Spray</li> <li value="csgo_type_collectible">Collectibles</li> <li value="csgo_type_ticket">Passes</li> <li value="csgo_tool_gifttag">Gifts</li> <li value="csgo_type_musickit">Music kits</li> <li value="csgo_type_weaponcase">Weapon Cases</li> <li value="csgo_tool_weaponcase_keytag">Keys</li> <li value="csgo_tool_patch">Patch</li> </ul>]
3- De ahí quiero extraer limpios los valores de li (solo lo que está dentro de "li value=" ) pero no soy capaz. Lo intento con:
for result in results:
elemento = result.find('li')
print(elemento)
pero solo me imprime una pequeña parte de los que hay en la lista, faltan muchos otros (además que sólo necesito el campo "value" nada más que eso):
<li value="weapon_knife_survival_bowie">Bowie Knife</li>
<li value="weapon_hkp2000">P2000</li>
<li value="weapon_galilar">Galil AR</li>
<li value="weapon_p90">P90</li>
<li value="weapon_bloodhound_gloves">Bloodhound Gloves</li>
<li value="crate_sticker_pack_community2022_capsule">Espionage</li>
<li value="csgo_type_tool">Tools</li>
Lo que necesito es obtener estos valores:
weapon_knife_survival_bowie
weapon_knife_butterfly
weapon_knife_falchion
weapon_knife_flip
...
así hasta que salgan todos