JeromeJ
Apify & Crawlee4y ago
2 replies
Jerome

Extracting text from list elements

I want to extract the text from all <li> elements inside an unordered list <ul>.
Trying
await page.locator("div.my_class > ul > li").textContent();
causes an error:
strict mode violation: locator('div.my_class > ul > li') resolved to x elements
. The presence of multiple elements is expected since this is a list.
Playwright itself doesn't seem to have an issue with selectors that return multiple elements, and I did find the
strictSelectors
parameter in the crawlee docs, but didn't manage to set it to false (if that is even the solution).
In scrapy
item.add_css("list", "div.my_class > ul > li::text")
returns a list of the text for each list item, which is what I'm looking for.
Does anyone know how to solve this?
Was this page helpful?