是否有一个相当于PHP Perl的WWW的::机械化? [英] Is there a PHP equivalent of Perl's WWW::Mechanize?

查看:171
本文介绍了是否有一个相当于PHP Perl的WWW的::机械化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个具有类似的功能Perl的 WWW库: :机械化,但对于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.

我知道卷曲,但它是一个有点太准系统,以及语法是pretty丑(吨 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将是一个很大的工作同样的事情,我不得不手工解析的页面找到的链接,找到这样的表格网址,提取所有的隐藏字段,等等。我问一个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 可以independendly从使用测试框架。我已经使用了大量的自动化作业。

SimpleTest's ScriptableBrowser can be used independendly from the testing framework. I've used it for numerous automation-jobs.

这篇关于是否有一个相当于PHP Perl的WWW的::机械化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆