Skip to content

Instantly share code, notes, and snippets.

@AWeirdDev
Created April 4, 2024 13:02
Show Gist options
  • Save AWeirdDev/fbb1cbf0950c16a77ffef3897b050723 to your computer and use it in GitHub Desktop.
Save AWeirdDev/fbb1cbf0950c16a77ffef3897b050723 to your computer and use it in GitHub Desktop.
Playwright: get discussion body for preprompt

replace {{ url }} to your discussion url

from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.webkit.launch()
page = browser.new_page()
page.goto("{{ url }}/body")
body = page.evaluate(
"""() => {
const body = document.querySelector('.d-block td');
let met = false;
let items = [];
body.childNodes.forEach(item => {
if (met) {
items.push(item.textContent)
}
if (item.tagName == "H1" && item.textContent == "Prompt") {
met = true
}
})
return items.join(`\n`).trim()
}"""
)
print(body)
browser.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment