- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 fandom wikia API 解析一些 json 数据。当我浏览到 my marvel.fandom.com/api request我得到以下 JSON 输出:{"batchcomplete":"","query":{"pages":{"45910":{"pageid":45910,"ns":0,"title":"Uncanny X 战警第 1 卷 171"}}}}
一开始没什么特别的,通过在线 JSON 解析器运行它会得到以下输出:
{
"batchcomplete":"",
"query":{
"pages":{
"45910":{
"pageid":45910,
"ns":0,
"title":"Uncanny X-Men Vol 1 171"
}
}
}
}
据我所知,这似乎没问题
我想获得其他几个请求的 pageid,但我似乎无法通过 Perl 获得相同的输出。脚本:
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use JSON;
use Data::Dumper;
my $url = "https://marvel.fandom.com/api.php?action=query&titles=Uncanny%20X-Men%20Vol%201%20171&format=json";
my $json = getprint( $url);
die "Could not get $url!" unless defined $json;
my $decoded_json = decode_json($json);
print Dumper($decoded_json);
但这会产生以下错误:
Could not get https://marvel.fandom.com/api.php?action=query&titles=Uncanny%20X-Men%20Vol%201%20171&format=json! at ./marvelScraper.pl line 11.
当我将 get 更改为 getprint 以获得一些额外信息时,我得到了这个:
500 Can't connect to marvel.fandom.com:443
<URL:https://marvel.fandom.com/api.php?action=query&titles=Uncanny%20X-Men%20Vol%201%20171&format=json>
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at ./script.pl line 13.
我在另一台电脑上试过了,仍然出现同样的错误。
LWP::Simple
和 LWP::Protocol::https
的版本
/usr/bin/perl -MLWP::Simple -E'say $LWP::Simple::VERSION'
6.15
/usr/bin/perl -MLWP::Protocol::https -E'say $LWP::Protocol::https::VERSION'
6.09
显然它与 Windows 上的 Bash Ubuntu 有关,因为在 Ubuntu 18.04 上我得到(使用相同的脚本)以下响应:
JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this) at ./test.pl line 13.
{"batchcomplete":"","query":{"pages":{"45910":{"pageid":45910,"ns":0,"title":"Uncanny X-Men Vol 1 171"}}}}
最佳答案
实际上,我的 Windows 上的 Bash Ubuntu
使用 get()
命令而不是 getprint()
命令运行完全相同的脚本在编辑您的问题后给出。
orabig@Windows:~/DEV$ ./so.pl
$VAR1 = {
'query' => {
'pages' => {
'45910' => {
'pageid' => 45910,
'ns' => 0,
'title' => 'Uncanny X-Men Vol 1 171'
}
}
},
'batchcomplete' => ''
};
所以也许您遇到了另一个与 Perl 或 Ubuntu 无关的问题。
你可以试试这个吗?
curl -v 'https://marvel.fandom.com/api.php?action=query&titles=Uncanny%20X-Men%20Vol%201%20171&format=json'
也许你只是访问网站太多了,500错误只是一些反盗链保护的结果?
关于json - 500 无法在 perl 中使用 lwp 连接到 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64882530/
我有两台 Windows 10 机器,在其中一台上,我安装了 Strawberry Perl(如果重要,版本 5.30.1)。我的脚本使用的是 REST::Client,在这台机器上,脚本运行完美。
已解决:我通过安装 HTML::HeadParser 修复了它。 但我仍然不知道为什么它突然停止工作。 我注意到一些以前有效的 LWP 请求已经停止工作,所以我制作了一个小脚本来检查原因。 出于某种原
新问题: 我正在使用我的 Perl 脚本执行以下操作: use strict; use warnings; use LWP 5.64; my $browser = LWP::UserAgent->ne
我想发布内容类型为 multipart/form-data 的数据: use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserA
案例一:我的服务器(远程访问没有互联网访问权限)在 443 端口连接到远程服务器。使用 Web 服务 URL,我需要发送 Web 服务请求并接收响应。我能够使用但无法从远程服务器接收响应来发送请求。代
有谁知道在 GET 或 POST 请求中仅获取网页 50% 的最佳方法?我获取的网页需要 10、20 秒才能完全加载,我只需要从页面开头过滤几行。 最佳答案 use 5.010; use strict
我正在使用 LWP 从网页下载内容,我想限制它等待页面的时间。这是在 lwp 中完成的,如下所示: my $ua = LWP::UserAgent->new; $ua->timeout(10); $u
我正在尝试向不可靠的服务器发出请求。这个请求很好,但不是 100% 需要我的 perl 脚本成功完成。问题是服务器偶尔会死锁(我们正在尝试找出原因)并且请求永远不会成功。由于服务器认为它是事件的,它保
我正在使用以下子例程运行 40 个左右的线程: my $app = shift; my $ua = LWP::UserAgent->new(); $ua->timeout(5); my $respon
我正在尝试向 https 服务器发出 LWP 请求。我已获得用户和通行证,建议使用基本身份验证。我尝试了各种代码块,但似乎都出现了身份验证错误。我当前的代码是... use warnings; use
代码如下: $vizFile ='https://docs.recipeinvesting.com/t.aaaf.html'; my $ua = LWP::UserAgent->new; $ua->t
我正在尝试让 LWP 请求对 https 服务器起作用。我已获得用户和通行证,建议使用基本身份验证。我尝试了各种代码块,但似乎都遇到了身份验证错误。我当前的代码是... use warnings; u
代码如下: $vizFile ='https://docs.recipeinvesting.com/t.aaaf.html'; my $ua = LWP::UserAgent->new; $ua->t
我正在尝试使用 LWP::UserAgent 设置凭据,但我无法登录。$username、$passwd 是正确的。我不明白我应该在第三个参数中输入什么(根据dos $realm,这里是Authent
我已经迁移到一个新的托管提供商,具有相同的 freebsd 系统,并且我的一个 perl 脚本停止正常工作。 它从外部 https 站点下载数据并将其存储在 mysql 数据库中。数据采用 cp125
以下脚本在运行 libwww-perl-5.836 的主机上返回综合 header ,但在使用 libwww-perl-6.30.0 的主机上不返回。在这种情况下,脚本会显示以下内容: 500
如何在 perl 中最佳地使用 LWP::UserAgent? 如果我需要进行多次 http 调用,我会重用同一个对象吗? 例如。 my $browser = LWP::UserAgent->new;
Java Thread 对象和 OS 线程(轻量级进程)之间是否存在一对一的映射。也就是说,如果我有一个 Thread 对象,我能否始终准确地识别一个关联的 OS 线程,并且我是否始终具有相同的关联
这句话是否正确:“Linux 中的所有线程都是 LWP 但并非所有 LWP 都是线程”。实际上,我试图了解Linux中的线程实现。 pthread_create 调用 clone 系统调用,但在 ma
my %parameters = ( key => 'value' ); my $response = $ua->ge
我是一名优秀的程序员,十分优秀!