We have API for that in soup now.
Created attachment 436173 [details] Patch
Committed r281489 (240863@main): <https://commits.webkit.org/240863@main>