- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我希望有人能帮我解决这个问题..
我有一个 python 脚本,可以从 html 文档中的标签中查找文本,我需要将它们写入以下格式的 csv 文件中:
Nessus,ID,文本
但现在我把它放在垂直线上:(
我的代码:
from bs4 import BeautifulSoup
import re
import csv
with open('xx01_med_dansk') as fp:
soup = BeautifulSoup(fp, 'html5lib')
# print(soup.prettify())
with open('dk_snip.csv', 'w') as f:
wr = csv.writer(f)
var1 = soup.find('li', text = re.compile('Scan vendor:'), attrs = {'class' : 'property_name'})
var2 = soup.find('li', text = re.compile('Vendor ID:'), attrs = {'class' : 'property_name'})
vendor = var1.find_next('li')
final = vendor.string
vend_id = var2.find_next('li')
final2 = vend_id.text
for dk_desc in soup.find_all(re.compile("textarea")):
final3 = dk_desc.text
to_csv = final+final2+final3
wr.writerows(to_csv)
我不太确定如何格式化数据以在 csv 文件中正确输入..
HTML 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<li class="property_name">
<label for="id_194-description">
Description:
</label>
</li>
<li class="property_value">
<textarea class="mceNoEditor" cols="40" id="id_194-description" name="194-description" rows="10" style="width:100%">According to its version, the installation of Oracle Database on the remote host is no longer supported.
Lack of support implies that no new security patches for the product will be released by the vendor. As a result, it is likely to contain security vulnerabilities.</textarea>
</li>
<li class="property_name">
<label for="id_194-consequence">
Consequence:
</label>
</li>
<li class="property_value">
<textarea class="mceNoEditor" cols="40" id="id_194-consequence" name="194-consequence" rows="10" style="width:100%">The remote host is running an unsupported version of a database server.</textarea>
</li>
<li class="property_name">
<label for="id_194-solution">
Solution:
</label>
</li>
<li class="property_value">
<textarea class="mceNoEditor" cols="40" id="id_194-solution" name="194-solution" rows="10" style="width:100%">Upgrade to a version of Oracle Database that is currently supported.</textarea>
</li>
<li class="property_name">
<label for="id_194-cve_id">
Cve id:
</label>
</li>
<li class="property_value">
<textarea class="mceNoEditor" cols="40" id="id_194-cve_id" maxlength="8192" name="194-cve_id" rows="10" style="width:100%; height:80px"></textarea>
</li>
<input id="id_194-override" name="194-override" type="hidden" value="11953"/>
<input id="id_194-priority" name="194-priority" type="hidden"/>
<li class="property_name">
Vulnerability priority
</li>
<li class="property_value">
<select name="prio_194">
<option selected="selected" value="0">
0
</option>
</select>
: Oracle Database Unsupported (Nessus)
<br/>
</li>
<li class="property_name">
Save
</li>
<li class="property_value">
<input type="submit" value="Save vulnerability changes"/>
</li>
</ul>
</form>
<br style="clear:both"/>
</div>
<div class="box">
<h4>
Related vulnerabilities
</h4>
<hr/>
<h5>
Oracle Database Unsupported (Nessus)
</h5>
<ul>
<li class="property_name">
Description
</li>
<li class="property_value">
According to its version, the installation of Oracle Database on the remote host is no longer supported.
<br/>
<br/>
Lack of support implies that no new security patches for the product will be released by the vendor. As a result, it is likely to contain security vulnerabilities.
</li>
<li class="property_name">
Consequence
</li>
<li class="property_value">
The remote host is running an unsupported version of a database server.
</li>
<li class="property_name">
Solution
</li>
<li class="property_value">
Upgrade to a version of Oracle Database that is currently supported.
</li>
</ul>
<br style="clear:both"/>
</div>
<div class="box">
<h4>
Create new snippet
</h4>
<form action="/report/vulnerabilityEditor/?
action=edit&
id=194&
sid=&
model=snippet" method="POST">
<ul>
<li class="property_name">
<label for="id_language">
Language:
</label>
</li>
<li class="property_value">
<select id="id_language" name="language" style="width:100%">
<option selected="" value="1">
Danish (DK)
</option>
<option value="2">
English (EN)
</option>
<option value="3">
Icelandic (IS)
</option>
</select>
</li>
<input id="id_vulnerability" name="vulnerability" type="hidden" value="194"/>
<li class="property_name">
<label for="id_title">
Title:
</label>
</li>
<li class="property_value">
<input id="id_title" maxlength="100" name="title" style="width:100%" type="text"/>
</li>
<li class="property_name">
<label for="id_recommendation">
Recommendation:
</label>
</li>
<li class="property_value">
<input id="id_recommendation" maxlength="255" name="recommendation" style="width:100%" type="text"/>
</li>
<li class="property_name">
<label for="id_snippet">
Snippet:
</label>
</li>
<li class="property_value">
<textarea cols="40" id="id_snippet" name="snippet" rows="10" style="width:100%"></textarea>
</li>
<li class="property_name">
Scan type
</li>
<li class="property_value">
<select multiple="multiple" name="scan_type" size="6" style="width:100%">
<option selected="selected" value="5">
COMPANY PCI
</option>
<option selected="selected" value="7">
Other
</option>
<option selected="selected" value="8">
Firewall Audit
</option>
<option selected="selected" value="6">
Penetration Test
</option>
<option selected="selected" value="9">
WIFI Test
</option>
<option selected="selected" value="10">
APP Test
</option>
<option selected="selected" value="1">
External Security Analysis
</option>
<option selected="selected" value="2">
Internal Security Analysis
</option>
<option selected="selected" value="3">
Web Application Test
</option>
<option selected="selected" value="4">
Host Discovery Analysis
</option>
</select>
-- Use ctrl to mark multiple types
</li>
<li class="property_name">
Save
</li>
<li class="property_value">
<input type="submit" value="Save new snippet"/>
</li>
</ul>
<br style="clear:both;"/>
</form>
</div>
<div class="box">
<h4>
Edit snippets
</h4>
<input id="property_vulnerability_id" type="hidden" value="194"/>
<input id="property_url_filter_snippets" type="hidden" value="/report/filterSnippets/"/>
<ul>
<li class="property_name">
Language
</li>
<li class="property_value">
<select id="language" name="language">
<option value="0">
All
</option>
<option value="1">
Danish
</option>
<option value="2">
English
</option>
<option value="3">
Icelandic
</option>
</select>
</li>
<li class="property_name">
Scan Type
</li>
<li class="property_value">
<select id="scantype" name="scantype">
<option value="0">
All
</option>
<option value="5">
COMPANY PCI
</option>
<option value="7">
Other
</option>
<option value="8">
Firewall Audit
</option>
<option value="6">
Penetration Test
</option>
<option value="9">
WIFI Test
</option>
<option value="10">
APP Test
</option>
<option value="1">
External Security Analysis
</option>
<option value="2">
Internal Security Analysis
</option>
<option value="3">
Web Application Test
</option>
<option value="4">
Host Discovery Analysis
</option>
</select>
</li>
</ul>
<br style="clear:both;"/>
<div class="snippet">
<form action="/report/vulnerabilityEditor/?action=edit&id=194&sid=1290&model=snippet" method="POST">
<input id="id_1290-vulnerability" name="1290-vulnerability" type="hidden" value="194"/>
<hr/>
<ul>
<li class="property_name">
<label for="id_1290-language">
Language:
</label>
</li>
<li class="property_value">
<select id="id_1290-language" name="1290-language" style="width:100%">
<option value="1">
Danish (DK)
</option>
<option selected="" value="2">
English (EN)
</option>
<option value="3">
Icelandic (IS)
</option>
</select>
</li>
<li class="property_name">
<label for="id_1290-title">
Title:
</label>
</li>
<li class="property_value">
<input id="id_1290-title" maxlength="100" name="1290-title" style="width:100%" type="text" value="Oracle Database Unsupported"/>
</li>
<li class="property_name">
<label for="id_1290-recommendation">
Recommendation:
</label>
</li>
<li class="property_value">
<input id="id_1290-recommendation" maxlength="255" name="1290-recommendation" style="width:100%" type="text" value="Upgrade to a version of Oracle Database that is currently supported."/>
</li>
<li class="property_name">
<label for="id_1290-snippet">
Snippet:
</label>
</li>
<li class="property_value">
<a href="https://cyberopswiki/index.php/How_to:_Add_figure_number_in_snippet" target="_blank">
How to: Add figure number in snippet.
</a>
</li>
<li class="property_value">
<textarea cols="40" id="id_1290-snippet" name="1290-snippet" rows="10" style="width:100%"><p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; text-align: justify; line-height: normal;"><span lang="EN-US" style="font-size: 10pt;">It has been detected, that the installed version of Oracle Application Server is&nbsp;<strong>XXXX.&nbsp;</strong>This version is known to be vulnerable to a number of unspecified vulnerabilities, categorized as 'urgent'.</span></p>
<p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; text-align: justify; line-height: normal;"><span lang="EN-US" style="font-size: 10pt;">As this version is no longer supported for this platform, updates or patches may no longer be released, which have the consequence that vulnerabilities can not be patched, leaving the system vulnerable.</span></p>
<p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; text-align: justify; line-height: normal;"><span lang="EN-US" style="font-size: 10pt;">In version 10.1.2.0.2 there are, according to http://www.cvedetails.com more than 54 vulnerabilities which affects the installed version.</span></p>
<p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; text-align: center; line-height: normal;" align="center"><strong><em><span lang="EN-US" style="font-size: 8pt;">Figure 1: </span></em></strong><em><span lang="EN-US" style="font-size: 8pt;">Oracle Application Server version.</span></em></p>
<p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; text-align: justify; line-height: normal;"><span lang="EN-US" style="font-size: 10pt;">More information on these vulnerabilities can be found at:&nbsp;</span><span style="font-size: 10pt;"><a href="http://www.cvedetails.com/vulnerability-list/vendor_id-93/product_id-707/version_id-26592/Oracle-Application-Server-10.1.2.0.2.html"><span lang="EN-US" style="color: blue; mso-ansi-language: EN-US;">http://www.cvedetails.com/vulnerability-list/vendor_id-93/product_id-707/version_id-26592/Oracle-Application-Server-10.1.2.0.2.html</span></a><a href="http://www.cvedetails.com/vulnerability-list/vendor_id-93/product_id-707/version_id-26592/Oracle-Application-Server-10.1.2.0.2.html"><span lang="EN-US" style="color: blue; mso-ansi-language: EN-US;">&nbsp;</span></a></span><span lang="EN-US" style="font-size: 10pt;">.</span></p>
<p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; text-align: justify; line-height: normal;">&nbsp;</p>
<p class="MsoNormal" style="mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; text-align: justify; line-height: normal;"><span lang="EN-US" style="font-size: 10pt;">It is recommended that the installed version is updated as soon as possible to the latest version.</span></p></textarea>
</li>
<li class="property_name">
Scan type
</li>
<li class="property_value">
<select multiple="multiple" name="scan_type" size="6" style="width:100%">
<option selected="selected" value="5">
COMPANY PCI
</option>
<option selected="selected" value="7">
Other
</option>
<option selected="selected" value="8">
Firewall Audit
</option>
<option selected="selected" value="6">
Penetration Test
</option>
<option selected="selected" value="9">
WIFI Test
</option>
<option selected="selected" value="10">
APP Test
</option>
<option selected="selected" value="1">
External Security Analysis
</option>
<option selected="selected" value="2">
Internal Security Analysis
</option>
<option selected="selected" value="3">
Web Application Test
</option>
<option selected="selected" value="4">
Host Discovery Analysis
</option>
</select>
-- Use ctrl to mark multiple types
</li>
<li class="property_name">
Update
</li>
<li class="property_value">
<input type="submit" value="Update snippet"/>
</li>
</ul>
</form>
<br style="clear:both;"/>
</div>
<div class="snippet">
<form action="/report/vulnerabilityEditor/?action=edit&id=194&sid=172&model=snippet" method="POST">
<input id="id_172-vulnerability" name="172-vulnerability" type="hidden" value="194"/>
<hr/>
<ul>
<li class="property_name">
<label for="id_172-language">
Language:
</label>
</li>
<li class="property_value">
<select id="id_172-language" name="172-language" style="width:100%">
<option selected="" value="1">
Danish (DK)
</option>
<option value="2">
English (EN)
</option>
<option value="3">
Icelandic (IS)
</option>
</select>
</li>
<li class="property_name">
<label for="id_172-title">
Title:
</label>
</li>
<li class="property_value">
<input id="id_172-title" maxlength="100" name="172-title" style="width:100%" type="text" value="Forældet Oracle Application Server 10g"/>
</li>
<li class="property_name">
<label for="id_172-recommendation">
Recommendation:
</label>
</li>
<li class="property_value">
<input id="id_172-recommendation" maxlength="255" name="172-recommendation" style="width:100%" type="text"/>
</li>
<li class="property_name">
<label for="id_172-snippet">
Snippet:
</label>
</li>
<li class="property_value">
<a href="https://cyberopswiki/index.php/How_to:_Add_figure_number_in_snippet" target="_blank">
How to: Add figure number in snippet.
</a>
</li>
<li class="property_value">
<textarea cols="40" id="id_172-snippet" name="172-snippet" rows="10" style="width:100%"><p style="font-size: 13px;">Det konstateret, at den installerede version af Oracle Application Server er&nbsp;<strong>XXXX.&nbsp;</strong>Denne version indeholder flere kendte samt uspecificeret s&aring;rbarheder, der kategoriseres som v&aelig;rende 'yderst kritiske' og 'kritiske'.</p>
<p style="font-size: 13px;">Da der ikke l&aelig;ngere komme opdateringer til denne platform, vil disse s&aring;rbarheder ikke blive udbedret, hvorfor systemet er meget udsat.</p>
<p style="font-size: 13px;">I version 10.1.2.0.2 findes der if&oslash;lge http://www.cvedetails.com ikke mindre end 54 s&aring;rbarheder, der ber&oslash;rer denne version. Mere information om disse findes p&aring; adressen&nbsp;<a href="http://www.cvedetails.com/vulnerability-list/vendor_id-93/product_id-707/version_id-26592/Oracle-Application-Server-10.1.2.0.2.html">http://www.cvedetails.com/vulnerability-list/vendor_id-93/product_id-707/version_id-26592/Oracle-Application-Server-10.1.2.0.2.html</a><a href="http://www.cvedetails.com/vulnerability-list/vendor_id-93/product_id-707/version_id-26592/Oracle-Application-Server-10.1.2.0.2.html">&nbsp;</a>.</p>
<p style="font-size: 13px;">Det anbefales leverand&oslash;ren af software l&oslash;sningen kontakts, s&aring; der hurtigst muligt kan opgraderes til en nyere, supporteret version.&nbsp;</p></textarea>
</li>
根据 Martins 的建议,我将代码修改如下:
from bs4 import BeautifulSoup
import re
import csv
import glob
def get_danish(text):
return re.compile(r'\b({0})\b'.format(text), flags=re.IGNORECASE).search
with open('dk_snip.csv', 'w', newline='') as f_out:
csv_out = csv.writer(f_out)
# csv_out.writerow(["Nessus", "ID", "Descrip"])
for filename in glob.glob('/home/rj/Documents/snip/snips/*'):
print("Processing:", filename)
with open(filename) as f_in:
soup = BeautifulSoup(f_in, 'html5lib')
var1 = soup.find('li', text = re.compile('Scan vendor:'), attrs = {'class' : 'property_name'})
var2 = soup.find('li', text = re.compile('Vendor ID:'), attrs = {'class' : 'property_name'})
vendor = var1.find_next('li').get_text(strip=True)
vend_id = var2.find_next('li').get_text(strip=True)
# rows = [[vendor, vend_id, dk_desc.get_text(strip=True)] for dk_desc in soup.find_all("textarea")[:3]]
for textarea in soup.find_all("textarea"):
desc = textarea.get_text(strip=True)
if get_danish('dette'):
csv_out.writerows([vendor, vend_id, desc])
最佳答案
您获得的标签需要被删除。一种方法是使用 BeautifulSoup .get_text(strip=True)
功能。
我假设您想要为每个 textarea
重复 Nessus
和 ID
值。下面显示了如何做到这一点:
from bs4 import BeautifulSoup
import csv
import re
import glob
import random
def get_language(text):
# This will need to be added using another library - currently random
return random.choice(["en", "dk"])
with open('dk_snip.csv', 'w', newline='') as f_out:
csv_out = csv.writer(f_out)
csv_out.writerow(["Nessus", "ID", "Text"])
for filename in glob.glob('*.html'): # search all HTML files in the current folder
print("Processing:", filename)
with open(filename) as f_in:
soup = BeautifulSoup(f_in, 'html5lib')
var1 = soup.find('li', text=re.compile('Scan vendor:'), attrs = {'class' : 'property_name'})
var2 = soup.find('li', text=re.compile('Vendor ID:'), attrs = {'class' : 'property_name'})
nessus = var1.find_next('li').get_text(strip=True)
id = var2.find_next('li').get_text(strip=True)
for textarea in soup.find_all("textarea"):
desc = textarea.get_text(strip=True)
if get_language(desc) == 'dk':
csv_out.writerow([nessus, id, desc])
这将为您提供以下输出 CSV 文件:
Nessus,ID,Text
Nessus,55786,"According to its version, the installation of Oracle Database on the remote host is no longer supported.
Lack of support implies that no new security patches for the product will be released by the vendor. As a result, it is likely to contain security vulnerabilities."
Nessus,55786,The remote host is running an unsupported version of a database server.
Nessus,55786,Upgrade to a version of Oracle Database that is currently supported.
注意:由于您的文本包含换行符,CSV 格式会自动用双引号将这些单元格括起来。它将正确加载到另一个包中。
该脚本搜索当前文件夹中的所有匹配文件。对于每个 textarea
,都会调用 get_language()
,需要使用另一个库进行编码。如果检测到 dk(或任何需要的内容),则该行将添加到 CSV 文件中。
如果您的文本区域包含 HTML,您可能需要使用对 BeautifulSoup 的另一个调用来进一步处理它:
soup_desc = BeautifulSoup(desc, 'html5lib')
for text in soup_desc.stripped_strings:
...
关于python - 将 html 写入 csv 时出现奇怪的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54905384/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!