I am attempting to write a code using beautiful soup that prints the text for the links in the left handed gray box on this webpage. In this case the code should return
** Enchantments Bouldering
Aasgard Sentinel
Argonaut Peak
Cashmere Mountain
Colchuck Balanced Rock
Colchuck Peak
Crystal Lake Tower
Dragontail Peak
Flagpole, The
Headlight Basin
Ingalls Peak
Jabberwocky Tower
Mt Stuart
Nightmare Needles
Prusik Peak
Rat Creek Spires
Sherpa Peak
Stuart Lake Basin
Viviane Campsite
Witches Tower
I am trying to generalize the wonderful answers to this very similar question, but when inspecting the source for my new web page, I can not find a table being used, and can’t decipher what the container is to reference in the following lines of code:
table = soup.find(lambda tag: tag.name=='???' and tag.has_attr('??') and tag['id']=="???")
rows = table.findAll(lambda tag: tag.name=='a')
2
Answers
if you already have the soup, then you just need to find the main container. here it’s a div of class
mp-sidebar
, then take all linksIt’s unclear what problem you’re having but to get the required output is trivial:
Output: