Download extract_playlist_playwright.py from p0000000/test: direct link, hf CLI and curl.
- Browser
- Download file 910 Bytes
-
https://huggingface.co/spaces/p0000000/test/resolve/main/extract_playlist_playwright.py
- Command line
-
hf download hf://spaces/p0000000/test/extract_playlist_playwright.py
-
curl -L -o extract_playlist_playwright.py https://huggingface.co/spaces/p0000000/test/resolve/main/extract_playlist_playwright.py
910 Bytes
| 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 | |