Skip to content

[DomCrawler] Ignore empty node exceptions #28313

Closed
@amer-flix

Description

@amer-flix

Description
When I try to access a node which does not exist in an XML / HTML, I get an exception:
The current node list is empty.

Current Solution:
I have to add try and catch for each statement or I have to check the ->count() for each statement.

Is it possible to ignore this error so that if it doesn't exist, it just keeps it empty / null?

Thanks

Example

// the following code throws an exception
$this->crawler->filter('marketingProductName')->text();

Metadata

Metadata

Assignees

No one assigned

    Labels

    DomCrawlerFeatureHelp wantedIssues and PRs which are looking for volunteers to complete them.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions