Keep scraping if element not found
This might be a question more closely related to js and playwright rather than Crawlee but let me give it a try.
Depending on the existence of an element on a page I want to decide if I should proceed with scraping or stop the process.
As I look for element with :
const element = await page.getByText("some text)
the crawler times out if the element doesnt show up
Any ideas how to implement this logic to proceed with scrape if the element is not found?2 Replies
optimistic-gold•3y ago
wrap in a try/catch
or chain a
.catch(()=>"")
on the promise
so ur script doesnt break n keep continuingadverse-sapphireOP•3y ago
JS basics, thanks
To expand if anyone is looking for a reference:
const element = await page.getByText("some text) will return a locator which is a truthy value so keep that in mind if using it in if statement