是否有相当于 Perl 的 WWW::Mechanize 的 PHP?
我正在寻找一个功能类似于 Perl 的WWW::Mechanize,但适用于 PHP.基本上,它应该允许我使用简单的语法提交 HTTP GET 和 POST 请求,然后解析结果页面并以简单格式返回所有表单及其字段以及页面上的所有链接.
I'm looking for a library that has functionality similar to Perl's WWW::Mechanize, but for PHP. Basically, it should allow me to submit HTTP GET and POST requests with a simple syntax, and then parse the resulting page and return in a simple format all forms and their fields, along with all links on the page.
我知道 CURL,但它有点过于准系统,而且语法非常难看(大量的 curl_foo($curl_handle, ...)
语句
I know about CURL, but it's a little too barebones, and the syntax is pretty ugly (tons of curl_foo($curl_handle, ...)
statements
说明:
我想要比目前的答案更高级的东西.例如,在 Perl 中,您可以执行以下操作:
I want something more high-level than the answers so far. For example, in Perl, you could do something like:
# navigate to the main page
$mech->get( 'http://www.somesite.com/' );
# follow a link that contains the text 'download this'
$mech->follow_link( text_regex => qr/download this/i );
# submit a POST form, to log into the site
$mech->submit_form(
with_fields => {
username => 'mungo',
password => 'lost-and-alone',
}
);
# save the results as a file
$mech->save_content('somefile.zip');
要使用 HTTP_Client 或 wget 或 CURL 做同样的事情将需要大量工作,我必须手动解析页面以查找链接、查找表单 URL、提取所有隐藏字段等.我要求 PHP 解决方案的原因是我没有使用 Perl 的经验,我可能可以通过大量工作来构建我需要的东西,但如果我能在 PHP 中完成上述操作,速度会快得多.>
To do the same thing using HTTP_Client or wget or CURL would be a lot of work, I'd have to manually parse the pages to find the links, find the form URL, extract all the hidden fields, and so on. The reason I'm asking for a PHP solution is that I have no experience with Perl, and I could probably build what I need with a lot of work, but it would be much quicker if I could do the above in PHP.
推荐答案
SimpleTest 的 ScriptableBrowser 可以独立于测试框架使用.我已经将它用于许多自动化工作.
SimpleTest's ScriptableBrowser can be used independendly from the testing framework. I've used it for numerous automation-jobs.
相关文章