小编slm*_*slm的帖子

Python Beautiful Soup如何将JSON解码为`dict`?

我是Python的BeautifulSoup的新手,我正试图dict从BeautifulSoup中提取.

我使用BeautifulSoup来提取JSON并获得beautifulsoup.beautifulsoup变量soup.

我试图从中获取价值soup,但是当我这样做时,result = soup.findAll("bill")我得到一个空列表[].如何提取汤以获得以下dict结果:

{u'congress': 113,
 u'number': 325,
 u'title': u'A bill to ensure the complete and timely payment of the obligations of the United States Government until May 19, 2013, and for other purposes.',
 u'type': u'hr'}


print type(soup)
print soup 
Run Code Online (Sandbox Code Playgroud)

=>结果如下

BeautifulSoup.BeautifulSoup

{
  "bill": {
    "congress": 113, 
    "number": 325, 
    "title": "A bill to ensure the complete and timely payment of the obligations of the United …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping

7
推荐指数
2
解决办法
4万
查看次数

Perl详细输出?

有没有一种方法可以像bash -x在Perl中一样获得Perl调试输出?

我不需要敲击或诊断消息(它们可以编译代码,但不打印Perl解释器执行的行)。

perl

7
推荐指数
1
解决办法
1万
查看次数

如何修复“无法匹配提供的主机模式,忽略:bigip”错误,适用于 Ansible,而不是 Tower

我在 VirtualBox 上运行的 ubuntu 16.04 VM 上运行 Ansible Tower v3.4.1 和 Ansible v2.7.6。我运行的剧本在我使用“ansible-playbook”从命令行运行时有效,但当我尝试从 Ansible Tower 运行时失败。我知道我一定在 ansible 塔中有一些配置错误的东西,但我找不到它。

无论我对清单(主机)文件进行什么更改,我都会收到此警告。

$ ansible-playbook 2.7.6

config file = /etc/ansible/ansible.cfg    
configured module search path = [u'/var/lib/awx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']

ansible python module location = /usr/lib/python2.7/dist-packages/ansible    

executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]

Using /etc/ansible/ansible.cfg as config file

SSH password:     
**/tmp/awx_74_z6yJB4/tmpVlXGCX did not meet host_list requirements**, check plugin documentation if this is unexpected

Parsed /tmp/awx_74_z6yJB4/tmpVlXGCX inventory source with …
Run Code Online (Sandbox Code Playgroud)

ansible ansible-inventory

7
推荐指数
2
解决办法
5万
查看次数

每秒监控tomcat请求?

如何使用collectd监视Tomcat中每秒的当前请求数.我正在考虑access.log使用脚本监视和计算请求,然后将其转换为collectd但是可能有更简单的方法吗?或者也许有一种更简单的方法来使用jmx?我只能找到每个线程的总请求和请求.

monitoring tomcat

6
推荐指数
1
解决办法
5486
查看次数

如何从调用它的perl程序中查看正在运行的程序的STDOUT?

我们试图弄清楚如何在perl脚本中运行java应用程序,但仍然可以定期从java应用程序的STDOUT中读取.

print "running dcmrcv.bat\n";

open my $fh_dcmrcv, "-|", 'z:\apps\dcm4che\dcm4che-2.0.26\bin\dcmrcv.bat \
  DCMRCV:11112 -dest z:\dcmrcv -journal z:\dcmrcv', 
  or die "could not execute dcmrcv: $!";

print "dcmrcv.bat started\n";
Run Code Online (Sandbox Code Playgroud)

我们希望能够每隔几分钟从文件句柄$ fh_dmcrcv中读取,或者可能通过在文件句柄上存在活动时设置AnyEvent io触发器来读取.

但是,当我尝试从文件句柄中读取时,如果我使用这样的东西,它就会阻塞:

foreach my $line (<$fh_dmcrcv>) {
  print $line;
}
Run Code Online (Sandbox Code Playgroud)

我们已经尝试了几种方法,不要以为我们可以使用File :: Tail,因为模块似乎需要一个实际的文件.问题似乎是$ fh_dcmrcv在我们阅读时阻止了我们,并不确定如何实现我们想要的正确方法.

编辑#1

当我们运行perl脚本时,我们看到的输出如下:

Z:\projects\demo_2>process_files.pl
running dcmrcv.bat
dcmrcv.bat started
Start Server listening on port 11112
11:55:13,495 INFO   - Start listening on 0.0.0.0/0.0.0.0:11112
Run Code Online (Sandbox Code Playgroud)

脚本process_files.pl正在发出消息:

running dcmrcv.bat
dcmrcv.bat started
Run Code Online (Sandbox Code Playgroud)

消息.从java程序是:启动服务器监听端口11112 11:55:13,495 INFO - 开始监听0.0.0.0/0.0.0.0:11112

在这种情况下,我们只是为了这个问题回应那些,我们真的想定期解析某些msgs.并且从不回应他们中的任何一个.

任何见解都表示赞赏,

萨姆

io perl file-io exec parent-child

6
推荐指数
1
解决办法
879
查看次数

使用deployJava.runApplet来定位特定元素

经过多年成功维护使用旧版本的applet:

<script src="foo.js"></script> 
Run Code Online (Sandbox Code Playgroud)

嵌入Java小程序的方法,我们无法掩盖我们的耳朵并唱"La la la!" 了.

是时候使用:

deployJava.runApplet()
Run Code Online (Sandbox Code Playgroud)

当我使用单击处理程序触发此方法时(此处通过jQuery在按钮上使用事件侦听器,但无关紧要):

$('#button').click(function() {
  deployJava.runApplet(attributes, parameters, version);
});
Run Code Online (Sandbox Code Playgroud)

...它会清除整个现有文档并将其替换为applet.我需要知道的是如何将特定的DOM元素作为applet的容器​​,这样我的页面就不会被擦除.

看起来它是一个我可以以target: someElement"someElement"是DOM对象或元素ID作为字符串的形式传递的属性.但是,我找不到这种属性的文档.

为了完成,以下是通过的内容:

/*here is where I imagine there might be an applicable attribute */
var attributes = {
  name: "SomeName",
  code: "some.class",
  archive: "some.jar",
  width: 640,
  height: 400
};

var parameters = {
  someParameter: someValue
};

var version = "1.5";
Run Code Online (Sandbox Code Playgroud)

我可以获得document.write重建文档所需的一切,但我相信你们都可以想象这个潜在客户在我看来是多么可怕.

任何指针都将非常感激.

javascript css java applet

6
推荐指数
1
解决办法
6784
查看次数

如何访问在multipart/form-data POST中上传的内容数据?

我在这个标题为:Perl HTTP服务器的 SO问答上找到了以下Perl代码.特别是这个答案.这是我修改过的代码:

httpserver.pl

#!/usr/bin/perl

use strict;
use warnings;

use CGI qw/ :standard /;
use Data::Dumper;
use HTTP::Daemon;
use HTTP::Response;
use HTTP::Status;
use POSIX qw/ WNOHANG /;

use constant HOSTNAME => qx{hostname};

my %O = (
    'listen-host' => '127.0.0.1',
    'listen-port' => 8080,
    'listen-clients' => 30,
    'listen-max-req-per-child' => 100,
);

my $d = HTTP::Daemon->new(
    LocalAddr => $O{'listen-host'},
    LocalPort => $O{'listen-port'},
    Reuse => 1,
) or die "Can't start http listener at $O{'listen-host'}:$O{'listen-port'}";

print "Started HTTP listener at " …
Run Code Online (Sandbox Code Playgroud)

forms perl curl http multipartform-data

6
推荐指数
1
解决办法
987
查看次数

在已知PID的不同进程中为bash设置陷阱

我需要为后台启动的bash进程设置一个陷阱.后台进程可能运行很长时间并将其PID保存在特定文件中.

现在我需要为该进程设置一个陷阱,所以如果它终止,PID文件将被删除.

有没有办法可以做到这一点?

编辑#1

看起来我对问题的描述看起来不够精确.我可以完全控制所有代码,但我拥有的长时间运行后台进程是这样​​的:

cat /dev/random >> myfile&
Run Code Online (Sandbox Code Playgroud)

当我现在在脚本的开头添加陷阱时,这个语句就在,$$将是那个更大的脚本的PID而不是我从这里开始的这个小后台进程.

那么如何具体为后台进程设置陷阱呢?

bash pid bash-trap

5
推荐指数
1
解决办法
2579
查看次数

在bash中计算文件中的Word出现次数

我很抱歉这个非常棒的问题,但我对bash编程很新(几天前开始).基本上我想要做的是保留一个文件与另一个文件的所有单词出现

我知道我可以这样做:

sort | uniq -c | sort
Run Code Online (Sandbox Code Playgroud)

事情是,之后我想要第二个文件,再次计算出现次数并更新第一个.我拿第三个文件后依此类推.

我现在正在做什么没有任何问题(我正在使用grep,sedawk),但它看起来很慢.

我很确定只有一个命令左右有一个非常有效的方法,使用uniq,但我无法弄清楚.

你能以正确的方式引导我吗?

我也粘贴了我写的代码:

#!/bin/bash
#   count the number of word occurrences from a file and writes to another file #
#   the words are listed from the most frequent to the less one                 #

touch .check                # used to check the occurrances. Temporary file
touch distribution.txt      # final file with all the occurrences calculated

page=$1             # contains the file I'm …
Run Code Online (Sandbox Code Playgroud)

linux bash shell uniq

5
推荐指数
1
解决办法
4888
查看次数

如何使用jinja2加入Ansible中的引号?

我有一个ansible列表值:

hosts = ["site1", "site2", "site3"]
Run Code Online (Sandbox Code Playgroud)

如果我试试这个:

hosts | join(", ")
Run Code Online (Sandbox Code Playgroud)

我明白了:

site1, site2, site3
Run Code Online (Sandbox Code Playgroud)

但我想得到:

"site1", "site2", "site3"
Run Code Online (Sandbox Code Playgroud)

ansible

5
推荐指数
1
解决办法
2765
查看次数