Wednesday, November 16, 2016

PHPDOMParser library's selectors are very whitespace-sensitive

PHP Simple DOM Parser is a very nice tool for parsing HTML using CSS-like tag selectors.

However, be very careful with whitespaces inside of selector expression,as they might cause silent failure. These are two different expressions:

$elem = $html->find(".container1[container_type=picture]>div", 0);

AND

$elem = $html->find(".container1[container_type=picture] > div", 0);

The second expression has 1 extra whitespace ( > ), and that will cause failure while trying to obtain the first div element inside container.

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...