我想移植一个使用机械化的iPhone应用程序.此应用需要登录网页并使用网站cookie转到该网站上的其他网页以获取一些数据.
使用我的python应用程序,我使用mechanize进行自动cookie管理.对于可移植到iPhone的Objective C有类似的东西吗?
谢谢你的帮助.
我正在寻找一个功能类似于Perl的WWW :: Mechanize的库,但是对于PHP.基本上,它应该允许我使用简单的语法提交HTTP GET和POST请求,然后解析生成的页面并以简单的格式返回所有表单及其字段,以及页面上的所有链接.
我知道CURL,但它有点过于简单,而且语法非常难看(大量的curl_foo($curl_handle, ...)陈述
澄清:
到目前为止,我想要比答案更高级的东西.例如,在Perl中,您可以执行以下操作:
# 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');
Run Code Online (Sandbox Code Playgroud)
要使用HTTP_Client或wget或CURL做同样的事情会有很多工作,我必须手动解析页面以查找链接,找到表单URL,提取所有隐藏字段,等等.我要求PHP解决方案的原因是我没有使用Perl的经验,而且我可以用很多工作构建我需要的东西,但如果我能在PHP中完成上述操作会更快.
我有很多脚本,其中大部分都是基于WWW::Mechanize可以通过HTTP访问的misc硬件中的数据.在升级我的大多数perl安装及其模块之后,使用HTTPS://的所有脚本都因为而破坏了"certificate verify failed"
这是因为较新版本的LWP对证书进行了适当的检查以及 dies是否存在不匹配的事实.
在我的情况下,由于情况,预计失败的证书认证,所以我需要找到一种干净地绕过这种检查的方法.
我在perl脚本上收到以下服务器错误:
来自脚本的格式错误的标题 错误的标头=:youtube_perl.pl,
这是我的源代码:
#!"C:\XAMPP\perl\bin\perl.exe" -T
use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use WWW::Mechanize;
my $q = CGI->new;
my $url = 'http://www.youtube.com';
my $mechanize = WWW::Mechanize->new(autocheck => 1);
$mechanize->get($url);
my $page = $mechanize->content();
print $page;
Run Code Online (Sandbox Code Playgroud)
提前致谢!
购买SSL证书后,我一直试图强制所有页面加密https和www.
https://www.exampl.com正在运行且安全,但只有在准确输入时才能使用.www.example.com或example.com仍然指向http.
我们使用nginx作为代理,需要在那里输入重写.我通过Putty进行SSH/root访问.我通过输入putty访问了nginx.conf.
怎么办?我是否在此页面上输入了nginx命令?从光标开始?任何命令行首先?
HTTPS:
.htacess - 在我发现我必须输入nginx之前给出的原始代码
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Run Code Online (Sandbox Code Playgroud)
Nginx代码转换器 - 这是它在转换器上显示的方式.一切都在正确的线上吗?
# nginx configuration location / {
if ($http_host ~* "^example.com"){
rewrite ^(.*)$ http://example.com/$1 redirect; } }
Run Code Online (Sandbox Code Playgroud)
然后
万维网
.htacess - 在我发现我必须输入nginx之前给出的原始代码
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
Run Code Online (Sandbox Code Playgroud)
Nginx代码转换器 - 这是它在转换器上显示的方式.一切都在正确的路线上吗?
# nginx configuration location / {
if ($http_host ~* "^example.com"){
rewrite ^(.*)$ http://www.example.com/$1 redirect; }
Run Code Online (Sandbox Code Playgroud)
}
我保存了吗?重新开始?
任何帮助将不胜感激.我已经和我斗争了好几个星期.我的托管公司尽可能地帮助,现在我正在学习...... 或者我应该停止并聘请开发人员?$$$ …
当我尝试使用以下代码下载一些HTML文件时:
$mech->get($link)
$mech->save_content("file.html");
Run Code Online (Sandbox Code Playgroud)
我收到警告:
Wide character in print at C:/strawberry/perl/site/lib/WWW/Mechanize.pm line 2040.
Run Code Online (Sandbox Code Playgroud)
有人可以解释我如何修复此警告吗?
我不确定以正确的方式为www mechanize设置脚本应用程序.我确实尝试过至少一个可行的备用,但是我试图通过测试传递配置,这样我就可以使测试套件更安静.
#!/usr/bin/perl
use strict;
use warnings;
use Dancer qw(:syntax);
use MyApp;
use Test::More;
use Test::WWW::Mechanize::PSGI;
set apphandler => 'PSGI';
set log => 'warning';
set logger => 'note';
my $mech = Test::WWW::Mechanize::PSGI->new(
app => dance, # app => do('bin/app.pl'), #
);
$mech->get_ok('/login') or diag $mech->content;
done_testing;
Run Code Online (Sandbox Code Playgroud)
do在脚本上运行似乎允许测试运行,但是日志变量没有正确设置,同时似乎有更好的方法来做到这一点.
更新
我想我可能会越来越接近一个解决方案......
#!/usr/bin/perl
use strict;
use warnings;
use FindBin;
use Cwd qw( realpath );
use Dancer qw(:syntax);
use MyApp;
use Test::More;
use Test::WWW::Mechanize::PSGI;
set apphandler => 'PSGI';
my $appdir = realpath( "$FindBin::Bin/.." …Run Code Online (Sandbox Code Playgroud) 所以我WWW::Mechanize用来抓取网站.它工作得很好,除非我请求一个网址,例如:
http://www.levi.com/
Run Code Online (Sandbox Code Playgroud)
我被重定向到:
http://us.levi.com/home/index.jsp
Run Code Online (Sandbox Code Playgroud)
对于我的脚本,我需要知道这个重定向发生了,我被重定向的网址是什么.无论如何使用WWW::Mechanize或检测到这个LWP然后获取重定向的URL?谢谢!
我有以下代码:
$mech->get($someurl, ":content_file" => "$i.flv");
Run Code Online (Sandbox Code Playgroud)
所以我得到一个url的内容并将其保存为flv文件.我想每隔一秒打印一下,剩下多少下载.有没有办法在WWW :: Mechanize中实现这一目标?
我正在搜索Node的模块,它类似于WWW :: Mechanize for Perl.甚至更好的WWW :: Mechanize :: Firefox.
如果有人知道类似的东西,或者我可以搜索哪个方向,那真的很感激.
www-mechanize ×10
perl ×6
lwp ×2
automation ×1
cookies ×1
dancer ×1
header ×1
https ×1
iphone ×1
javascript ×1
mechanize ×1
nginx ×1
node.js ×1
objective-c ×1
perl-module ×1
php ×1
progress-bar ×1
psgi ×1
redirect ×1
ssl ×1
testing ×1
url ×1