arrow_back
Back

Web scraping in PHP: HTML parsers

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

HTML parsers

Options for parsing HTML in PHP, roughly from worst to best:

  • Regular expressions — technically possible, but fragile and hard to maintain for real HTML.
  • open_in_new phpQuery — jQuery-style API, but no longer actively maintained.
  • PHP Simple HTML DOM Parser — jQuery-like selectors, also fairly old.
  • open_in_new DiDOM — the most actively maintained of the three, and the recommended default choice.

Related: proxies , CAPTCHA solving .

PHP Simple HTML DOM Parser

open_in_new Homepage .

Using

Selecting an element:

$page_content->find("#product_enabled", 0)->plaintext;
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

cURL in PHP: GET, POST, cookies, and proxies

arrow_forward