r/PHPhelp • u/Fyreborn • Aug 07 '22
Best PHP library options for scraping sites with JavaScript - Symfony Panther, Chrome-PHP, Mink, etc.?
I am looking for a PHP browser tool that I can use to scrape websites that require execution of JavaScript, and can click JavaScript links. I'm not entirely sure what the terminology is, I think it's browser emulators or browser controllers.
I've found these:
https://github.com/symfony/panther
https://github.com/chrome-php/chrome
https://github.com/minkphp/Mink
I've seen some articles on scraping that mention Symfony Panther, but haven't seen the others mentioned anywhere.
Symfony Panther - 2.6K stars, 57 watching, 206 forks, used by 9.8K, 85 contributors, last updated August 2
Chrome-PHP - 1.5K stars, 43 watching, 201 forks, used by 139, 38 contributors, last updated July 8
Mink - 1.5K stars, 38 watching, 267 forks, used by 25.8K, 85 contributors, last updated March 28
They seem to have fairly similar stats except for users, where Mink has 25.8K while Panther has 9.8K and Chrome-PHP only 139.
I don't know exactly how to choose between these, and if there's any other options in PHP (I know there's other options in Python and Node.JS, but I'm looking for one in PHP). I don't know if some are easier to use, or faster, etc.
I also found this Mink-Panther driver, I'm a newbie so I'm not sure what Mink even is exactly, or what this is quite supposed to do.
https://github.com/robertfausk/mink-panther-driver
Sorry for being vague, but I'm afraid I don't have enough knowledge on this subject to even know which questions to ask.
Are there any other PHP libraries that can be used to scrape JavaScript websites and click JavaScript links? And how should I choose between them? Is there some that are considered better than others, or do they all do roughly the same thing?
1
u/swolicheert 12d ago
quick landscape clarification since the stats hide what these actually are: Mink is a browser-abstraction layer built for testing (Behat) that drives other backends, it's not really a scraping tool, i'd skip it here, its high 'used by' is all test suites. Symfony Panther drives a real Chrome/Firefox over WebDriver (runs js, clicks links), it's the most documented for what you want. Chrome-PHP (chrome-php/chrome) talks to headless chrome directly over CDP, lighter than Panther since there's no webdriver server, and its low 'used by' just means less adoption, not lower quality. so between them: Panther if you want docs/examples, Chrome-PHP if you want leaner. but the bigger thing: before you commit to bundling headless chrome into a php app (it's heavy to run and deploy), check whether you need js at all. open dev tools > network > fetch/xhr, because 'execute js and click links' is very often just the page requesting a json endpoint or navigating to url-param pages the js builds, and if so you can hit those directly with Guzzle (already in your stack) and skip the browser entirely, way faster and simpler. only if it's truly client-rendered with no endpoint do you need Panther/Chrome-PHP. and since headless chrome in php is genuinely painful to run in prod, if the target also blocks bots a scraping api like scrapfly returns the rendered html so you don't host chromium yourself. but check the network tab first.