Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用Nokogiri解析nessus HTTP响应?_Html_Ruby_Nokogiri - Fatal编程技术网

Html 使用Nokogiri解析nessus HTTP响应?

Html 使用Nokogiri解析nessus HTTP响应?,html,ruby,nokogiri,Html,Ruby,Nokogiri,我正在nessus xmlrpc gem中构建一个功能,以允许下载HTML报告。我现在只需要解析HTML响应的文件名值 以下是我使用的nessus的示例响应: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Formatting the report</title><meta http-equiv="refresh" content="5;url=

我正在nessus xmlrpc gem中构建一个功能,以允许下载HTML报告。我现在只需要解析HTML响应的文件名值

以下是我使用的nessus的示例响应:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Formatting the report</title><meta http-equiv="refresh"
content="5;url=/file/xslt/download/?fileName=Windows_-_Main___Media_kr1sjb.html">
</head>
<body bgcolor="#2b4e67">
<link type="text/css" href="jqueryui18.css" rel="stylesheet" />
<script type="text/javascript" src="jqueryui18.js"></script>
<div id="main"></div>
文档的结尾如下所示:

#<Nokogiri::HTML::Document:0x4758128 name="document" children=[#<Nokogiri::XML::DTD:0x4757f48 name="html">, #<Nokogiri::XML::Element:0x47578ea name="html" children=[#<Nokogiri::XML::Element:0x47577aa name="head" children=[#<Nokogiri::XML::Element:0x475767e name="meta" attributes=[#<Nokogiri::XML::Attr:0x475764c name="charset" value="utf-8">]>, #<Nokogiri::XML::Element:0x4757368 name="title" children=[#<Nokogiri::XML::Text:0x475723c "Formatting the report">]>, #<Nokogiri::XML::Element:0x475af9a name="meta" attributes=[#<Nokogiri::XML::Attr:0x475ac48 name="http-equiv" value="refresh">, #<Nokogiri::XML::Attr:0x475ac2a name="content" value="5;url=/file/xslt/download/?fileName=Windows_-_Main___Media_kr1sjb.html">]>]>, #<Nokogiri::XML::Element:0x470b968 name="body" attributes=[#<Nokogiri::XML::Attr:0x470b7ec name="bgcolor" value="#2b4e67">] children=[#<Nokogiri::XML::Element:0x46fb216 name="link" attributes=[#<Nokogiri::XML::Attr:0x46fb18a name="type" value="text/css">, #<Nokogiri::XML::Attr:0x46fb176 name="href" value="jqueryui18.css">, #<Nokogiri::XML::Attr:0x46fb16c name="rel" value="stylesheet">]>, #<Nokogiri::XML::Element:0x46fa1d6 name="script" attributes=[#<Nokogiri::XML::Attr:0x46fa0e6 name="type" value="text/javascript">, #<Nokogiri::XML::Attr:0x46fa0c8 name="src" value="jqueryui18.js">]>, #<Nokogiri::XML::Element:0x46dd43c name="div" attributes=[#<Nokogiri::XML::Attr:0x46dd37e name="id" value="main">]>]>]>]>
#
我不知道如何取回
fileName
值“Windows\u-Main\u\u Media\u kr1sjb.html”

任何帮助都将是非常好的,一旦这些更改生效,我将推动所有这些更改。

我将按以下方式执行:

require 'nokogiri'

doc = Nokogiri::HTML.parse <<-eol
<html>
<head>
<meta charset="utf-8">
<title>Formatting the report</title><meta http-equiv="refresh"
content="5;url=/file/xslt/download/?fileName=Windows_-_Main___Media_kr1sjb.html">
</head>
<body bgcolor="#2b4e67">
<link type="text/css" href="jqueryui18.css" rel="stylesheet" />
<script type="text/javascript" src="jqueryui18.js"></script>
<div id="main"></div>
eol

str = doc.at_css('meta[http-equiv="refresh"]')['content']
# => "5;url=/file/xslt/download/?fileName=Windows_-_Main___Media_kr1sjb.html"
str[/\?fileName=(.*)/,1]
# => "Windows_-_Main___Media_kr1sjb.html"
需要“nokogiri”
doc=Nokogiri::HTML.parse“Windows_-\u Main\uuu u Media\u kr1sjb.HTML”

好吧,我必须捕获一个响应,因此我将上面的html文档放在一个名为http\u content的变量中。我将如何调整您的方法,使其正常工作?
require 'nokogiri'

doc = Nokogiri::HTML.parse <<-eol
<html>
<head>
<meta charset="utf-8">
<title>Formatting the report</title><meta http-equiv="refresh"
content="5;url=/file/xslt/download/?fileName=Windows_-_Main___Media_kr1sjb.html">
</head>
<body bgcolor="#2b4e67">
<link type="text/css" href="jqueryui18.css" rel="stylesheet" />
<script type="text/javascript" src="jqueryui18.js"></script>
<div id="main"></div>
eol

str = doc.at_css('meta[http-equiv="refresh"]')['content']
# => "5;url=/file/xslt/download/?fileName=Windows_-_Main___Media_kr1sjb.html"
str[/\?fileName=(.*)/,1]
# => "Windows_-_Main___Media_kr1sjb.html"