skip to Main Content

I’ve created a script in python to parse different links from a webpage. There are two section in the landing page. One is Top Experiences and the other is More Experiences. My current attempt can fetch the links from both the categories.

The type of links I wanna collect are (few of them) under the Top Experiences section at this moment. However, when I traverse the links under More Experiences section, I can see that they all lead to the page in which there is a section named Experiences under which there are links that are similar to the links under Top Experiences in the landing page. I wanna grab them all.

One such desirable link I’m after looks like: https://www.airbnb.com/experiences/20712?source=seo.

website link

My current attempt fetches the links from both the categories:

import requests
from urllib.parse import urljoin
from bs4 import BeautifulSoup

URL = "https://www.airbnb.com/sitemaps/v2/experiences_pdp-L0-0"

def get_links(link):
    res = requests.get(link)
    soup = BeautifulSoup(res.text,"lxml")
    items = [urljoin(link,item.get("href")) for item in soup.select("div[style='margin-top:16px'] a._1f0v6pq")]
    return items

if __name__ == '__main__':
    for item in get_links(URL):
        print(item)

How can I parse all the links under Top Experiences section along with the links under Experiences section that can be found upon traversing the links under More Experiences?

Please check out the image if anything unclear. I used a pen available in paint so the writing may be a little hard to understand.

4

Answers


  1. Seem like both the “Top Experience” and “More experiences” links share the same class so you can just use .find_all to obtain the links.

    import requests
    #from urllib.parse import urljoin
    from bs4 import BeautifulSoup
    
    # URL to scrape
    url = "https://www.airbnb.com/sitemaps/v2/experiences_pdp-L0-0"
    
    # Make request and Initialize BS4 with request content
    req = requests.get(url)
    soup = BeautifulSoup(req.content, "lxml")
    
    # Tag that contains "Top Experiences" and "More Experiences"
    soup.find_all(class_="_l8g1fr")
    
    # Test Code
    #Prints title of links and the href
    links = soup.find_all(class_="_l8g1fr")
    for link in links:
        print(link.find("a").get_text())
        print(link.find("a").get('href'))
    
    

    Refactor code to meet your coding paradigm.

    Login or Signup to reply.
  2. You can scrape from the divs with class "_12kw8n71":

    from bs4 import BeautifulSoup as soup
    import requests
    d = soup(requests.get('https://www.airbnb.com/sitemaps/v2/experiences_pdp-L0-0').text, 'html.parser')
    a, b, *_ = d.find_all('div', {'class':'_12kw8n71'})
    result = {'top_experiences':[[i.text, i['href']] for i in a.find_all('a')], 'more_experiences':[[i.text, i['href']] for i in b.find_all('a')]}
    

    Output (Only top experiences and part of the links from more experiences, as the full output exceeds Stackoverflow’s character limit):

    {'top_experiences': [["#1 HOLLYWOOD SIGN TOUR - WORLD'S BEST", '/experiences/26790?source=seo'], ['**#1-COMEDY/INSTAGRAM HOLLYWOOD WALK**', '/experiences/94033?source=seo'], ["A Potter's Wheel in Brooklyn", '/experiences/139532?source=seo'], ['Absolute: Seoul Pub Crawl & Party', '/experiences/161886?source=seo'], ['Amsterdam Experience Cruise', '/experiences/145329?source=seo'], ['Argentine Tango classes in London', '/experiences/241771?source=seo'], ['Axe throwing Canadian Experience', '/experiences/372251?source=seo'], ['Be a chocolate maker for a day', '/experiences/161912?source=seo'], ['Chianti in a Glass', '/experiences/179469?source=seo'], ['Cooking class in the Chianti Hills', '/experiences/25122?source=seo'], ['Cycle and Snack through hidden Bangkok', '/experiences/315116?source=seo'], ['Discover Valpolicella', '/experiences/77468?source=seo'], ["Don't watch Soweto, be part of Soweto", '/experiences/243188?source=seo'], ['Explore Pompeii w/ an Archaeologist', '/experiences/176605?source=seo'], ['Explore backstreets with a historian', '/experiences/90528?source=seo'], ['Explore the hidden food gems of Athens', '/experiences/256850?source=seo'], ['Fall and Winter Forest Trail Rides', '/experiences/236040?source=seo'], ['Foodies of Palermo - street food tour', '/experiences/212673?source=seo'], ['Forge a silver ring with jewellers', '/experiences/209198?source=seo'], ['Handmade Family Pasta & Tiramisù', '/experiences/115906?source=seo'], ['Hidden Gems of Old Delhi', '/experiences/154177?source=seo'], ['Hike Runyon Canyon with a rescue dog', '/experiences/82265?source=seo'], ['Hike Table Mountain with a Guide!', '/experiences/137248?source=seo'], ['Kayak in La Jolla', '/experiences/132375?source=seo'], ['Lakehouse Jazz', '/experiences/53239?source=seo'], ["Lisbon's best flavors", '/experiences/64564?source=seo'], ["London's Top Sights Tour : Fun Guide!", '/experiences/203605?source=seo'], ['Make ramen noodles from scratch', '/experiences/61279?source=seo'], ['Mount Etna excursion and lava tubes', '/experiences/221142?source=seo'], ['Must Have L.A. Pictures!', '/experiences/59665?source=seo'], ['MySurf School Bali', '/experiences/153910?source=seo'], ['PASTAMANIA', '/experiences/103280?source=seo'], ['Paddle with the Penguins', '/experiences/112515?source=seo'], ['Paella Maestro', '/experiences/51311?source=seo'], ["Paris' Best Kept Secrets Tour", '/experiences/113388?source=seo'], ['Play, Walk & Feed  Anteaters +Kinkajou', '/experiences/270405?source=seo'], ['Red Dunes Safari & BBQ @The Real Camp', '/experiences/105242?source=seo'], ['San José Chocolate Tasting Tour', '/experiences/280822?source=seo'], ['Snorkel in Manly with a local expert', '/experiences/66873?source=seo'], ['Sunrise SUP into Caves & Grottos', '/experiences/242911?source=seo'], ['Sushi-making Experience', '/experiences/53271?source=seo'], ['Swim with sea lions in their natural habitat', '/experiences/327235?source=seo'], ['The Drinking & Prohibition walk', '/experiences/102778?source=seo'], ['The Ultimate Harry Potter Walking Tour', '/experiences/188432?source=seo'], ['Tsukiji (Old) vs Toyosu (New) S.S Tour', '/experiences/71924?source=seo'], ['Wolf Encounter', '/experiences/47240?source=seo'], ['XXL Wild&Organic Roman food: Eat&Learn', '/experiences/161461?source=seo'], ['Your First Chinese Seal-engraving Work', '/experiences/166172?source=seo'], ['Под руку с духами по старой Москве', '/experiences/94558?source=seo'], ["⭐BIKE to taste the world's BEST TACOS!", '/experiences/75047?source=seo']], 'more_experiences': [[" Flying Trapeze  - 'Ten Things I Hate About You' Tour", '/sitemaps/v2/experiences_pdp-L1-0'], ["'The Devil in the White City' Tour - 23:59 in Paris", '/sitemaps/v2/experiences_pdp-L1-1'], ["24h en Republica Dominicana - 80s  Cover Band's Secret Gig[FUKUOKA]", '/sitemaps/v2/experiences_pdp-L1-2'], ['80s Nights - A Journey Through History', '/sitemaps/v2/experiences_pdp-L1-3'], ["A Journey for the Tastebuds, in Malaga - A Tea Sommelier's Zen Tea Party", '/sitemaps/v2/experiences_pdp-L1-4'], ['A Time for Home - A music walk with a french composer', '/sitemaps/v2/experiences_pdp-L1-5'], ['A musical walk in Salzburg - ANALOG PHOTOGRAPHY in DC!  Shoot FILM!', '/sitemaps/v2/experiences_pdp-L1-6'], ['ANGEL, ENERGIA GASTRONOMICA ANCESTRAL! - Acuarela al aire libre en Poblenou', '/sitemaps/v2/experiences_pdp-L1-7'], ['Acupuncture in Historic Clinic - Afternoon tea at the Casavant Villa', '/sitemaps/v2/experiences_pdp-L1-8'], ["Afterwork dans un Atelier d'Artistes - Alpine Raft Expérience", '/sitemaps/v2/experiences_pdp-L1-9'], ['Alpine Tour Skiing Uphill/Downhill - Amélie en live!', '/sitemaps/v2/experiences_pdp-L1-10'], ['An African Dance & Cultural Experience - Another BKK', '/sitemaps/v2/experiences_pdp-L1-11'], ['Another Etna: Trekking, Food and Wine - Aprende o perfecciona bailes caribeños', '/sitemaps/v2/experiences_pdp-L1-12'], ['Aprende una actividad unica de Oaxaca - Around historical area with lovely dog', '/sitemaps/v2/experiences_pdp-L1-13'], ['Around the Neva & its embankments - Art tour Soumaya & Jumex Museums visit', '/sitemaps/v2/experiences_pdp-L1-14'], ['Art tour at Bellas Artes - Ascent to the crater of the Puracé volcano', '/sitemaps/v2/experiences_pdp-L1-15'], ['Asciende a la cima del Batea Mahuida - Atlas Mountains Day Trip: imlil Valley', '/sitemaps/v2/experiences_pdp-L1-16'], ['Atlas Mountains Full day Cultural Trip - Authentic Tango Night', '/sitemaps/v2/experiences_pdp-L1-17'], ['Authentic Tango with Live Music - BIARRITZ WALKING HISTORICAL TOUR', '/sitemaps/v2/experiences_pdp-L1-18'], ['BIG SUP Fun - Paddle Sevilla! - Bake ‘Dorayaki’ Japanese pancake', '/sitemaps/v2/experiences_pdp-L1-19'], ['Bakery Hop with Perth Brunch Bloggers - Banyuatis-Munduk Amazing Bike Tour', '/sitemaps/v2/experiences_pdp-L1-20'], ["Baptism of Rome for First-Timers - Batik: What's That?", '/sitemaps/v2/experiences_pdp-L1-21'], ['Batom vermelho - um estilo de vida - Beach Exercise Under The Sun', '/sitemaps/v2/experiences_pdp-L1-22'], ['Beach FlowJAM - Become Captain of the Day with Vicky', '/sitemaps/v2/experiences_pdp-L1-23'], ['Become Reiki 1 Certified in Hawaii! - Beginner Workshop', '/sitemaps/v2/experiences_pdp-L1-24'], ['Beginner and Kid Friendly Kayak Tour - Best Croissants + Coffee of Paris Walk', '/sitemaps/v2/experiences_pdp-L1-25'], ['Best Dirt Biking Experience in KL! - Big Easy Food Tours', '/sitemaps/v2/experiences_pdp-L1-26'], ['Big Fish In The Big Apple - Bike the Wineries', '/sitemaps/v2/experiences_pdp-L1-27'], ['Bike the local backroads - Birdwatching al Parco del Circeo', '/sitemaps/v2/experiences_pdp-L1-28'], ['Birdwatching and camping - Boat Trip at Arrabida with Lunch', '/sitemaps/v2/experiences_pdp-L1-29'], ['Boat Trip to historic Clonmacnoise - Boozin in Brooklyn: Spirits & Beer', '/sitemaps/v2/experiences_pdp-L1-30'], ["Boozy Icy Secrets - Breakfast Coffee Yoga @ Kellogg's Cafe", '/sitemaps/v2/experiences_pdp-L1-31'], ['Breakfast With The (Chicago) Bear - Brugge voor jou.', '/sitemaps/v2/experiences_pdp-L1-32'], ['Brumby (wild) Horse Experience - Bushwalk with Bob', '/sitemaps/v2/experiences_pdp-L1-33'], ["Bushwalking; Airlie's best kept secret - Cabalgata, pasión por la aventura.", '/sitemaps/v2/experiences_pdp-L1-34'], ['Cabalgatas "Buscando el sol de ayer" - Camina por el parque observando aves', '/sitemaps/v2/experiences_pdp-L1-35'], ['Camina por la Historia de  Jujuy - Canoeing with Champagne and Pastries', '/sitemaps/v2/experiences_pdp-L1-36'], ['Canoeing, Kayaking, Cycling in Catba - Capture your relationship in photos', '/sitemaps/v2/experiences_pdp-L1-37'], ['Capture your smile in beautiful hanbok - Catalonia Sailing Xperience', '/sitemaps/v2/experiences_pdp-L1-38'], ['Catalonia from Above - Cervantes Tapas Crawl Alcalá d Henares', '/sitemaps/v2/experiences_pdp-L1-39'], ['Cervezas artesanales de Querétaro - Cherry blossom viewing party in Ueno', '/sitemaps/v2/experiences_pdp-L1-40'], ['Cherry blossoms and your photo session - Chocolate tasting and tour', '/sitemaps/v2/experiences_pdp-L1-41'], ['Chocolate therapy - City Tour With Visit to Teatro Colon', '/sitemaps/v2/experiences_pdp-L1-42'], ['City Tour around Cali - Climb a sea cliff in El Empordà coast', '/sitemaps/v2/experiences_pdp-L1-43'], ['Climb an iconic hill with an instructor - Cocktails and Canapés', '/sitemaps/v2/experiences_pdp-L1-44'], ['Cocktails and Canvas - Columbia River King Salmon Fishing', '/sitemaps/v2/experiences_pdp-L1-45'], ['Columbus Cemetery. History and Art - Conhecendo o centro do recife', '/sitemaps/v2/experiences_pdp-L1-46'], ['Conhecendo o litoral e as belas praias - Cook  great traditional dish with Heba', '/sitemaps/v2/experiences_pdp-L1-47'], ['Cook  with Cristiana and Mamma Nora - Cook shelf mania.. authentic n savory', '/sitemaps/v2/experiences_pdp-L1-48'], ['Cook tapas at a secret private eatery - Cooking Spanish "tapas"', '/sitemaps/v2/experiences_pdp-L1-49'], ['Cooking Spanish classics with Soul! - Copenhagen Skyline Art Workshop', '/sitemaps/v2/experiences_pdp-L1-50'], ['Copenhagen Small Group Tour - Couture dans un atelier de Montmartre', '/sitemaps/v2/experiences_pdp-L1-51'], ["Covered Walkways Through a Writer’s Eyes - Crawlin' in the City - Bar Crawl", '/sitemaps/v2/experiences_pdp-L1-52'], ["Crazy French Sauces - Create a Story in a Writer's Retreat", '/sitemaps/v2/experiences_pdp-L1-53'], ['Create a Travel Journal - Create with a pro tie-dye artist', '/sitemaps/v2/experiences_pdp-L1-54'], ['Create wooden guitar picks and jewelry - Creative Raw Vegan Cooking Workshop', '/sitemaps/v2/experiences_pdp-L1-55'], ['Creative Rendezvous in Copenhagen - Créer ses cosmétiques naturels (DIY)', '/sitemaps/v2/experiences_pdp-L1-56'], ['Créer un Mandala Energétique - Cupcake Bake & Decorate - Spitalfields', '/sitemaps/v2/experiences_pdp-L1-57'], ['Cupcake Bouquet Class - Cycling in quiet NE. Connecticut.', '/sitemaps/v2/experiences_pdp-L1-58'], ['Cycling in the Don Valley - DJ WORKSHOP IN AACHEN GEBE DEN TAKT AN', '/sitemaps/v2/experiences_pdp-L1-59'], ['DJ Workshop and Indie Scene Night - Dark tour of Split', '/sitemaps/v2/experiences_pdp-L1-60'], ['Darkroom Photography in Kuala Lumpur - Decorative Wreath Workshop', '/sitemaps/v2/experiences_pdp-L1-61'], ['Decoupage for DIY memorabilia & gifts - Descubre México a través de la foto', '/sitemaps/v2/experiences_pdp-L1-62'], ['Descubre Playa Blanca, Saltos - Design a Garment in the World Market', '/sitemaps/v2/experiences_pdp-L1-63'], ['Design a game level in a game studio - Dinghy Sailing at El Portet', '/sitemaps/v2/experiences_pdp-L1-64'], ['Dingle Traditional Rowing - Discover CDMX from the best Rooftops', '/sitemaps/v2/experiences_pdp-L1-65'], ['Discover Caen "Art de vivre" - Discover Manzanita Scavenger Hunt', '/sitemaps/v2/experiences_pdp-L1-66'], ["Discover Marrakech Secrets by Bike - Discover Tarraco's living history", '/sitemaps/v2/experiences_pdp-L1-67'], ['Discover Tarragona coast from the sea - Discover nd paint your Aztec protector', '/sitemaps/v2/experiences_pdp-L1-68'], ['Discover new flavors with an oenophile - Discover the cosmos', '/sitemaps/v2/experiences_pdp-L1-69'], ['Discover the emotion of Kitesurf - Discovering Montjuic Hill', '/sitemaps/v2/experiences_pdp-L1-70'], ['Discovering Old Medina of Casablanca - Diving, Dipping, Swiming in Varadero', '/sitemaps/v2/experiences_pdp-L1-71'], ['Dj Workshop - Downtown Toronto Photoshoot Experience', '/sitemaps/v2/experiences_pdp-L1-72'], ['Downtown Traditional Cantina Pub Crawl - Drinking&Eating with Tokyohandsomeboy', '/sitemaps/v2/experiences_pdp-L1-73'], ['Drinks and  a Show Walking Tour - Découverte des dauphins', '/sitemaps/v2/experiences_pdp-L1-74'], ['Découverte des spiritueux québécois - EL FASCINANTE MUNDO DEL MOSAICO', '/sitemaps/v2/experiences_pdp-L1-75'], ['ELDORADO: sus plantas y lugares. - Eat Like a Local - Dinner Experience', '/sitemaps/v2/experiences_pdp-L1-76'], ['Eat Like a Local at Butterworth - Eco Friendly Ranch & Petting Zoo', '/sitemaps/v2/experiences_pdp-L1-77'], ['Eco Hike in Pinar del Rio - Electric Skateboard down Paris', '/sitemaps/v2/experiences_pdp-L1-78'], ['Electric Skateboard the Highline Canal - Enigmatic / Sintra', '/sitemaps/v2/experiences_pdp-L1-79'], ['Enjoin Local Meal By Taking Vegetable - Enjoy local food experience in Tokyo!', '/sitemaps/v2/experiences_pdp-L1-80'], ['Enjoy local western part of Jeju ! - Escalada en Roca en Acantilados Valpo', '/sitemaps/v2/experiences_pdp-L1-81'], ['Escalada en Tarifa - Everyone Can Dance! Brussels', '/sitemaps/v2/experiences_pdp-L1-82'], ['Everyone can do Calligraphy - Experience Fabulous698B! Spring menu!', '/sitemaps/v2/experiences_pdp-L1-83'], ['Experience Falconry Firsthand - Experience a tasting menu in Saigon', '/sitemaps/v2/experiences_pdp-L1-84'], ['Experience a traditional Sunday lunch - Experiencia de golf en Buenos Aires', '/sitemaps/v2/experiences_pdp-L1-85'], ['Experiencia de un día en Salamanca - Explore Bowen Island Walking Adventure', '/sitemaps/v2/experiences_pdp-L1-86'], ['Explore Brazilian cuisine with a chef - Explore Korea broadcast Town & MBC', '/sitemaps/v2/experiences_pdp-L1-87'], ['Explore Korčula with Art historian - Explore Saratoga Passage by Kayak', '/sitemaps/v2/experiences_pdp-L1-88'], ['Explore Sceneries of Sokcho - Explore city nightlife with a musician', '/sitemaps/v2/experiences_pdp-L1-89'], ['Explore city nightlife with locals! - Explore the Old District Sham Shui Po', '/sitemaps/v2/experiences_pdp-L1-90'], ['Explore the Oslo Wilderness in Kayak - Exploring  Maspalomas by E-Scooter', '/sitemaps/v2/experiences_pdp-L1-91'], ['Exploring  RawaPening Lake of Salatiga - FOOTBALL MATCH IN MEDELLIN', '/sitemaps/v2/experiences_pdp-L1-92'], ['FOREST BATHING AND CREATING MEMORIES - Fantasy Photo~Shoot with A Unicorn...', '/sitemaps/v2/experiences_pdp-L1-93'], ['Fantasy adventure in the mountains - Fazendo Arte na Serra da Cantareira!', '/sitemaps/v2/experiences_pdp-L1-94'], ['Faça acrobacia em tecido como circense - Film your experience in Osaka', '/sitemaps/v2/experiences_pdp-L1-95'], ['FilmNeverDies-Filmphotography Workshop - Fishing with the Presidents', '/sitemaps/v2/experiences_pdp-L1-96'], ['Fishing, Malecon and Sunset - Florist in Paris', '/sitemaps/v2/experiences_pdp-L1-97'], ['Florist terrace & aperol spritz - Follow a historian through Havana', '/sitemaps/v2/experiences_pdp-L1-98'], ['Follow a local in vibrant East London - Food, Fotos & The French', '/sitemaps/v2/experiences_pdp-L1-99'], ['Food, Nature and Art on Tuscan Hills - Fossil Recovery Exploration', '/sitemaps/v2/experiences_pdp-L1-100'], ['Fossil hunting, Lets GO! - French food market tour & aperitif', '/sitemaps/v2/experiences_pdp-L1-101'], ['French macarons baking class - Full day surf experience', '/sitemaps/v2/experiences_pdp-L1-102'], ['Full day trail ride - Gaelic Craic and Cuisine', '/sitemaps/v2/experiences_pdp-L1-103'], ['Gain insight from a spiritual healer - Gems of Rome...', '/sitemaps/v2/experiences_pdp-L1-104'], ['Generations of Beekeeping - Get uplifted with gospel in Harlem', '/sitemaps/v2/experiences_pdp-L1-105'], ['Get ur Shine On Moonshine/Whiskey Tour - Glenorchy and Paradise Explorer', '/sitemaps/v2/experiences_pdp-L1-106'], ['Gliding on the Ice in the Red Dot - Goat Yoga!', '/sitemaps/v2/experiences_pdp-L1-107'], ['Goatherd for one day! - Graffiti, Street & Young Art in Vienna', '/sitemaps/v2/experiences_pdp-L1-108'], ['Grampians hike & waterfalls - Guide tours with E-bike in Menorca', '/sitemaps/v2/experiences_pdp-L1-109'], ['Guided  Photo Tour ART Walk - Guitar workshop for the Byron Vibe', '/sitemaps/v2/experiences_pdp-L1-110'], ['Gulf Coast Birding For Beginners - Hand Building with clay in Brooklyn', '/sitemaps/v2/experiences_pdp-L1-111'], ['Hand Coffee Roasting & Cupping Class - Hang loose w/ Island Style Surf School', '/sitemaps/v2/experiences_pdp-L1-112'], ['Hang out in Shibuya and craft bonsai - Have a personal photographer for a day', '/sitemaps/v2/experiences_pdp-L1-113'], ['Have a picnic in a national park - Helicopter tour from Paris to Versailles', '/sitemaps/v2/experiences_pdp-L1-114'], ['Helicopter tour in São Paulo - Hidden Sculpture Stories Tour', '/sitemaps/v2/experiences_pdp-L1-115'], ['Hidden Sights & Cosmopolitan Magic - Hike Forest+ City Summit+ Rose Garden', '/sitemaps/v2/experiences_pdp-L1-116'], ['Hike Gracia hills for view & workout - Hike the Braids and Blackford Hill', '/sitemaps/v2/experiences_pdp-L1-117'], ['Hike the Bridge to Nowhere - Hiking Ajusco (1day)', '/sitemaps/v2/experiences_pdp-L1-118'], ['Hiking Ancient Mountain Olive Trees - Hill Country Estate Winery Tour', '/sitemaps/v2/experiences_pdp-L1-119'], ['Hill Country Yoga Hike - History and Tapas', '/sitemaps/v2/experiences_pdp-L1-120'], ['History and art inside Tijuca forest - Home-based cooking class in Panaji', '/sitemaps/v2/experiences_pdp-L1-121'], ['Home-cooked traditional Indian Food - Horseback ride California cowboy style', '/sitemaps/v2/experiences_pdp-L1-122'], ['Horseback ride and lunch with a farmer - Hungarian Cooking Class & Market Walk', '/sitemaps/v2/experiences_pdp-L1-123'], ['Hungarian pasta workshop and dinner - Ikebana experience', '/sitemaps/v2/experiences_pdp-L1-124'], ['Ikebana exprence - In the middle of the wet forest.', '/sitemaps/v2/experiences_pdp-L1-125'], ['In the trails of Rio - Inside Scoop LA', '/sitemaps/v2/experiences_pdp-L1-126'], ['Inside Showjumping with a Journalist - Interactive experience of lightpainting room', '/sitemaps/v2/experiences_pdp-L1-127'], ['Interactive outdoor navigation course - Invigorating Yoga Flow at Balboa Park', '/sitemaps/v2/experiences_pdp-L1-128'], ['Invitation To Ginza Personal Shopping - JUNGLE ART WALK TULUM', '/sitemaps/v2/experiences_pdp-L1-129'], ['JUNGLE IN THE CITY - Jazz in Cape Town with Lee Thomson', '/sitemaps/v2/experiences_pdp-L1-130'], ['Jazz in a Secret Venue - Joshua Tree Macramé Journey', '/sitemaps/v2/experiences_pdp-L1-131'], ['Joshua Tree Recording Studio & Lodging - Kamikochi hike and visit the Shrine', '/sitemaps/v2/experiences_pdp-L1-132'], ['Kanazawa Haul at Depachika - Kayak with the Dolphins', '/sitemaps/v2/experiences_pdp-L1-133'], ['Kayak&Snorkeling experience in Genoa - Kitesurf In Lake Garda', '/sitemaps/v2/experiences_pdp-L1-134'], ['Kitesurf Lecce-Scuola Kite Salento - Kundalini Yoga to awaken Inner Lover', '/sitemaps/v2/experiences_pdp-L1-135'], ['Kundalini Yoga, Gong and Yogi Tea - LGBTQ+ History Tour of Brighton', '/sitemaps/v2/experiences_pdp-L1-136'], ['LGBTQ+ queer and trans tour of London - Lamawandern im Mostviertel', '/sitemaps/v2/experiences_pdp-L1-137'], ['Lamb Farm Life - Learn 3D printing at Maker Bean Cafe!', '/sitemaps/v2/experiences_pdp-L1-138'], ['Learn 3D printing: design a souvenir - Learn Pencak Silat (Bali Martial Art)', '/sitemaps/v2/experiences_pdp-L1-139'], ['Learn Phone Photography in Mongkok - Learn and indulge in Quercy cuisine', '/sitemaps/v2/experiences_pdp-L1-140'], ['Learn and play poker in Barão Geraldo - Learn how to wakeboard', '/sitemaps/v2/experiences_pdp-L1-141'], ['Learn how to wakeboard or wakesurf - Learn to DJ and dance at a queer club', '/sitemaps/v2/experiences_pdp-L1-142'], ['Learn to DJ at Private Studio - Learn to bake sourdough in my kitchen', '/sitemaps/v2/experiences_pdp-L1-143'], ['Learn to bake traditional Irish Breads - Learn to play badminton!', '/sitemaps/v2/experiences_pdp-L1-144'], ['Learn to play poker from a Vegas pro - Legends and secrets with traditional music', '/sitemaps/v2/experiences_pdp-L1-145'], ["Lei Po'o (Flower Crown) Workshop - Let's learn how to wearing kimono", '/sitemaps/v2/experiences_pdp-L1-146'], ["Let's learn to SKETCH & DRAW! - Life changing Hike on Crowders Mtn.", '/sitemaps/v2/experiences_pdp-L1-147'], ['Life coaching with horses - Lisbon with the historic tram', '/sitemaps/v2/experiences_pdp-L1-148'], ["Lisbon's CatWalk - Living the Santa Cruz Canyon!", '/sitemaps/v2/experiences_pdp-L1-149'], ['Living the dying city! - London Chicken Wing Tour!', '/sitemaps/v2/experiences_pdp-L1-150'], ['London Christmas Lights Running Tour - Luis Barragán en 5 tiempos.', '/sitemaps/v2/experiences_pdp-L1-151'], ['Lujan de Cuyo Private Wine Tour - Macaron Class in Paris', '/sitemaps/v2/experiences_pdp-L1-152'], ["Macaron Masterclass in Borough - Makati's best food drinks and music", '/sitemaps/v2/experiences_pdp-L1-153'], ['Make  Fujiyama Katsu-Curry with a chef - Make Wine Candles+Bottle Cutting (DIY)', '/sitemaps/v2/experiences_pdp-L1-154'], ['Make Your Leather Tortellino Keychain - Make a seashell frame after a boatride', '/sitemaps/v2/experiences_pdp-L1-155'], ['Make a signature scent with a perfumer - Make sushi in a traditional folk house', '/sitemaps/v2/experiences_pdp-L1-156'], ['Make sustainable leather espadrilles - Make your own silk scarf in Paris !', '/sitemaps/v2/experiences_pdp-L1-157'], ['Make your own silver jewel in Florence - Malen und Zeichnen', '/sitemaps/v2/experiences_pdp-L1-158'], ['Maleny Yoga Rainforest Wellness - Market Tour and a Home Cooked Meal', '/sitemaps/v2/experiences_pdp-L1-159'], ['Market Tour&Cook  Kenyan cultural food - Matera Photo Journey', '/sitemaps/v2/experiences_pdp-L1-160'], ['Mathematics Walking Tour of Amsterdam - Meditazione  rilassamento profondo', '/sitemaps/v2/experiences_pdp-L1-161'], ['Meditazione e benEssere in spiaggia - Men & Womens Wellness Retreat', '/sitemaps/v2/experiences_pdp-L1-162'], ['Mental Wellness Picnic Chat - Midday Vermouth Madrileño & Tortilla', '/sitemaps/v2/experiences_pdp-L1-163'], ['Middle Eastern Food Cooking Class - Mini Horse Experience!', '/sitemaps/v2/experiences_pdp-L1-164'], ['Mini Nature Retreat - Moniz Family Surf: Private Surf Lesson', '/sitemaps/v2/experiences_pdp-L1-165'], ['Moniz Family Surf: Waikiki Surf Lesson - Morocco in frames:Culture &photography', '/sitemaps/v2/experiences_pdp-L1-166'], ['Mortadella & Bologna: a love story - Mountain plateau hike (5-7 hr)', '/sitemaps/v2/experiences_pdp-L1-167'], ['Mountain summit and cozy restaurant - Music, Mummies, and Museums!', '/sitemaps/v2/experiences_pdp-L1-168'], ['Music, art, history, Rio nightlife - NEW! Amsterdam light cruise', '/sitemaps/v2/experiences_pdp-L1-169'], ['NEW! Aperitivo tour - Fun Fun Fun! ❤️ - National Arboretum and #madeinDC Tour', '/sitemaps/v2/experiences_pdp-L1-170'], ['National Gallery with an Art Historian - Nature trails & Birding near Cali', '/sitemaps/v2/experiences_pdp-L1-171'], ['Nature walk near Hotspring in Jozankei - Night Cheese: California Artisans', '/sitemaps/v2/experiences_pdp-L1-172'], ["Night Cherry Viewing - Nonna Cecilia's Pasta Workshop!", '/sitemaps/v2/experiences_pdp-L1-173'], ['Noodle & Roll & Water Puppet Theater - Obstacle Course Adventure', '/sitemaps/v2/experiences_pdp-L1-174'], ['Ocean Beach Coffee Cart Bike Tour - Old Montreal: Intimate & Personalized', '/sitemaps/v2/experiences_pdp-L1-175'], ['Old Quebec : Mesdames & Mesdemoiselles - Ontdek de ambacht van het jam maken', '/sitemaps/v2/experiences_pdp-L1-176'], ['OoLong Tea Tasting - Osaka Old City Walk Tour with  Sweets!', '/sitemaps/v2/experiences_pdp-L1-177'], ['Osaka Shinsekai/Dotonbori Walking Tour - PASTA MATRICIANA   MAKING CLASS', '/sitemaps/v2/experiences_pdp-L1-178'], ['PASTA grani antichi  PANE lievito nat - Paddle with the Penguins', '/sitemaps/v2/experiences_pdp-L1-179'], ['Paddle your way in history - Paint a skateboard deck with an artist', '/sitemaps/v2/experiences_pdp-L1-180'], ['Paint a surfboard to send home! - Painting on the Amalfi Coast.', '/sitemaps/v2/experiences_pdp-L1-181'], ['Painting on the Pier - Paris fabrics & crafts', '/sitemaps/v2/experiences_pdp-L1-182'], ['Paris for Families - Passeio a cavalo no por do Sol', '/sitemaps/v2/experiences_pdp-L1-183'], ['Passeio agradável no bairro do Bexiga! - Pedal untamed back roads of Outaouais', '/sitemaps/v2/experiences_pdp-L1-184'], ['Pedala nelle pinete di Ravenna - Personal Shopping Consultant', '/sitemaps/v2/experiences_pdp-L1-185'], ['Personal Shopping For Bespoke Suits - Photo Session in beautiful Basel', '/sitemaps/v2/experiences_pdp-L1-186'], ['Photo Session in sunny Ibiza - Photo tour of Dublin city', '/sitemaps/v2/experiences_pdp-L1-187'], ["Photo tour on bike with an expert - Photographing in 'off-piste' Tokyo.", '/sitemaps/v2/experiences_pdp-L1-188'], ['Photographing in Palermo markets - Photoshoot for yoga lovers in Paris', '/sitemaps/v2/experiences_pdp-L1-189'], ['Photoshoot from Varadero to Havana - Pick plant n Cook,KANOM JAAK,dessert', '/sitemaps/v2/experiences_pdp-L1-190'], ['Pick wild apples and can applesauce - Pizza Class on a Renaissance Terrace', '/sitemaps/v2/experiences_pdp-L1-191'], ['Pizza Cooking Class in Milan - Play the Chinese ink art with Runkuan', '/sitemaps/v2/experiences_pdp-L1-192'], ['Play the Fiddle in Under an Hour - Por los Cerros de Santiago.', '/sitemaps/v2/experiences_pdp-L1-193'], ['Por los cementerios de Chepe. - Pose for pin-ups with a photographer', '/sitemaps/v2/experiences_pdp-L1-194'], ['Pose for portraits in Cambridge - Prague experience: archaeology&history', '/sitemaps/v2/experiences_pdp-L1-195'], ['Prague for Locals and You - Private Alpine Backpacking Trip', '/sitemaps/v2/experiences_pdp-L1-196'], ['Private Amalfi & Positano HalfDay tour - Private Yoga Class & Eco Snack', '/sitemaps/v2/experiences_pdp-L1-197'], ['Private Yoga Class for All Levels - Professional photos of your LA Vacay!', '/sitemaps/v2/experiences_pdp-L1-198'], ['Professional photoshoot by the sea - Pêche dans le Parc du Mercantour', '/sitemaps/v2/experiences_pdp-L1-199'], ['Pêche des Calamars en mer - Rafting the Isar', '/sitemaps/v2/experiences_pdp-L1-200'], ['Rafting trip-Snorkeling&cliff jumping - Recording Studio Magic (Immersive)', '/sitemaps/v2/experiences_pdp-L1-201'], ['Recording your own k-pop song - Relaxing Costarican Typical Trails', '/sitemaps/v2/experiences_pdp-L1-202'], ['Relaxing Countryside : Somewhere Snowy - Ride OFF Road in Puerto Rico', '/sitemaps/v2/experiences_pdp-L1-203'], ['Ride Retired Racehorses at Lake Fork - River hike captured on drone video', '/sitemaps/v2/experiences_pdp-L1-204'], ['River view cooking with super mom chef - Romancing the Bean', '/sitemaps/v2/experiences_pdp-L1-205'], ['Romantic "Aperitivo" with lake view - Rugged North Cascades Private Day Tour', '/sitemaps/v2/experiences_pdp-L1-206'], ['Ruin Pub Crawl with a Local Hostess - Running Tour of Brooklyn!', '/sitemaps/v2/experiences_pdp-L1-207'], ['Running Tour of San Diego - SAORI freestyle weaving for everyone', '/sitemaps/v2/experiences_pdp-L1-208'], ['SASHIKO; Learn the Japanese embroidery - SUP around Balboa Isle & the Back Bay', '/sitemaps/v2/experiences_pdp-L1-209'], ['SUP at sunset - Sail around the city with a boat lover', '/sitemaps/v2/experiences_pdp-L1-210'], ['Sail at Sunset in Porto - Sails, Whales, and Trails', '/sitemaps/v2/experiences_pdp-L1-211'], ['Sailtour Lake Lucerne - Samurai Kendo Experience', '/sitemaps/v2/experiences_pdp-L1-212'], ['Samurai Ninja Experience & Guided Tour - Sardinia: sip by sip', '/sitemaps/v2/experiences_pdp-L1-213'], ['Sardinian identity in the kitchen - Scotch Whisky & Cheese Tasting', '/sitemaps/v2/experiences_pdp-L1-214'], ['Scotland Adventure Adrenaline Day - Seaside Yoga', '/sitemaps/v2/experiences_pdp-L1-215'], ['Seaside bike ride and paddle surfing - Secretos de la Perla Tapatía', '/sitemaps/v2/experiences_pdp-L1-216'], ['Secretos del centro de Coyoacán - Segeln in Berlin', '/sitemaps/v2/experiences_pdp-L1-217'], ['Segeltörn auf dem Steinhuder Meer - Seville From The Rooftops', '/sitemaps/v2/experiences_pdp-L1-218'], ['Seville Great Experience in E-Bike - Shmurgle a Goat, Cosy Winter Edition', '/sitemaps/v2/experiences_pdp-L1-219'], ['Shochu tasting workshop in Asakusa - Shop-til-you-drop with Fashion Stylist', '/sitemaps/v2/experiences_pdp-L1-220'], ['Shopper bag making class - Silicon Valley High Tech Company Tour', '/sitemaps/v2/experiences_pdp-L1-221']]}
    
    Login or Signup to reply.
  3. Process:

    1. Get all Top Experiences links

    2. Get all More Experiences links

    3. Send a request to all More Experiences links one by one and get the links under Experiences in each page.

    The div under which the links are present are same for all the pages have the same class _12kw8n71

    import requests
    from urllib.parse import urljoin
    from bs4 import BeautifulSoup
    from time import sleep
    from random import randint
    URL = "https://www.airbnb.com/sitemaps/v2/experiences_pdp-L0-0"
    res = requests.get(URL)
    soup = BeautifulSoup(res.text,"lxml")
    top_experiences= [urljoin(URL,item.get("href")) for item in soup.find_all("div",class_="_12kw8n71")[0].find_all('a')]
    more_experiences= [urljoin(URL,item.get("href")) for item in soup.find_all("div",class_="_12kw8n71")[1].find_all('a')]
    generated_experiences=[]
    #visit each link in more_experiences
    for url in more_experiences:
        sleep(randint(1,10))#avoid blocking by putting some delay
        generated_experiences.extend([urljoin(URL,item.get("href")) for item in soup.find_all("div",class_="_12kw8n71")[0].find_all('a')])
    

    Notes:

    1. Your required links will be present in three lists top_experiences , more_experiences and generated_experiences

    2. I have added random delay to avoid getting blocked.

    3. Not printing the lists as it will be too long.

      top_experiences – 50 links

      more_experiences – 299 links

      generated_experiences -14950 links

    Login or Signup to reply.
  4. The solution is slightly tricky. It can be achieved in several ways. The one I find most useful is use the links under More Experiences within get_links() function recursively. All the links under More Experiences have a common keyword _pdp-.

    So, when you define condional statement within the function to make the links sieve through the function get_links() recursively then the else block will produces the desired links. Most important thing to notice is that all the desired links are within the class _1f0v6pq So the logic of getting the links is fairly easy .

    import requests
    from urllib.parse import urljoin
    from bs4 import BeautifulSoup
    
    URL = "https://www.airbnb.com/sitemaps/v2/experiences_pdp-L0-0"
    
    def get_links(link):
        res = requests.get(link)
        soup = BeautifulSoup(res.text,"lxml")
        for item in soup.select("div[style='margin-top:16px'] a._1f0v6pq"):
            if "_pdp-" in item.get("href"):
                get_links(urljoin(URL,item.get("href")))
            else:
                print(urljoin(URL,item.get("href")))
    
    if __name__ == '__main__':
        get_links(URL)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search