Skip to content

Instantly share code, notes, and snippets.

@LucianBuzzo
Created March 3, 2025 15:26
Show Gist options
  • Select an option

  • Save LucianBuzzo/957e4dcb9cccaf5512d1d39e56953cb0 to your computer and use it in GitHub Desktop.

Select an option

Save LucianBuzzo/957e4dcb9cccaf5512d1d39e56953cb0 to your computer and use it in GitHub Desktop.
Genius song lyrics scraper
import { test } from "@playwright/test";
const userAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
test.use({
userAgent,
});
test("Genius", async ({ page }) => {
const searchQuery = "under pressure";
const url = `https://genius.com/search?q=${encodeURIComponent(searchQuery)}`;
await page.goto(url);
await page.locator('div[aria-label="Privacy"]').getByText("I accept").click();
await page.locator(".mini_card").first().click();
await page.locator("#lyrics-root").waitFor({ state: "visible" });
const lyrics = await page.locator("#lyrics-root").innerText();
console.log(lyrics);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment