File size: 910 Bytes
630fa47
4cf9a45
 
630fa47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from playwright.async_api import async_playwright

async def extract_playlist(url):
    songs = []
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page()
        await page.goto(url)
        await page.wait_for_selector('div.songs-list-row__song-name-wrapper')
        items = await page.query_selector_all('div.songs-list-row__song-name-wrapper')
        for item in items:
            title_el = await item.query_selector('div.songs-list-row__song-name')
            artist_el = await item.query_selector('div.songs-list-row__by-line')
            title = await title_el.inner_text() if title_el else "Unknown Title"
            artist = await artist_el.inner_text() if artist_el else "Unknown Artist"
            songs.append({'title': title.strip(), 'artist': artist.strip()})
        await browser.close()
    return songs