views:

912

answers:

3

I was wondering if there was anything similar like Mechanize or BeautifulSoup for PHP?

+4  A: 

SimpleTest provides you with similar functionality:

http://www.lastcraft.com/browser_documentation.php

Jon
SimpleTest Browser class indeed does seem to do the job right however I was looking for something lighter, perhaps some library not oriented for Unit Testing?
Alix Axel
You can use SimpleTest's browser without the rest of the framework. It's a self-contained subcomponent.
troelskn
require_once(dirname(__FILE__) . '/simpletest.php'); and a dozen of other includes.
Alix Axel
+2  A: 

I don't know how powerful BeautifulSoup is, so maybe this won't be as great ; but you could try using DOMDocument::loadHTML :

The function parses the HTML contained in the string source . Unlike loading XML, HTML does not have to be well-formed to load.

After using this, you should be able to access the HTML document using DOM methods -- including XPath queries.

Pascal MARTIN
+1 for the native suggestion, although doing XPath queries is several times more complex than doing the same thing in BeautifulSoup.
Alix Axel
oh :-( too bad ^^
Pascal MARTIN
+1  A: 

Don't know about BeautifulSoup, but there is phpquery which is similar to jquery

$doc = phpQuery::newDocument('<div/>');

$doc['div']->append('<ul></ul>');
$doc['div ul'] = '<li>1</li><li>2</li><li>3</li>';

$doc['ul > li:last'] = 'hello';
carlosz
Thanks, SimpleTest seems a little superior however I'll give this one a look.
Alix Axel