首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在python中从xml文件中拉取特定对象

在python中从xml文件中拉取特定对象
EN

Stack Overflow用户
提问于 2020-11-02 09:38:37
回答 1查看 13关注 0票数 1

尝试仅剥离此xml页面中列出的域名:https://us-cert.cisa.gov/sites/default/files/publications/AA20-301A.stix.xml

因此,从下面的数据可以看出:

代码语言:javascript
复制
<indicator:Title>Malicious FQDN Indicator</indicator:Title>
<indicator:Type xsi:type="stixVocabs:IndicatorTypeVocab-1.1">Domain Watchlist</indicator:Type>
<indicator:Observable id="CISA:Observable-1a97193f-7206-4bda-aadb-a9876943629b">
<cybox:Object id="CISA:Object-8ee878fd-147c-4438-be3a-ad61470eec80">
<cybox:Properties xsi:type="DomainNameObj:DomainNameObjectType" type="FQDN">
<DomainNameObj:Value condition="Equals">jp-ssl[.]work</DomainNameObj:Value>
</cybox:Properties>
</cybox:Object>
</indicator:Observable>
<indicator:Sightings sightings_count="1">
<indicator:Sighting timestamp="2018-05-01T00:00:00"/>
</indicator:Sightings>
</stix:Indicator>
<stix:Indicator id="CISA:Indicator-90e0da37-5c97-49f1-8fe5-5a4db57513fa" timestamp="2020-10-23T18:29:40.163791+00:00" xsi:type="indicator:IndicatorType">
<indicator:Title>Malicious FQDN Indicator</indicator:Title>
<indicator:Type xsi:type="stixVocabs:IndicatorTypeVocab-1.1">Domain Watchlist</indicator:Type>
<indicator:Observable id="CISA:Observable-40f4bf4d-db81-4560-bbaa-73ce4a9ead99">
<cybox:Object id="CISA:Object-da253d57-6148-435a-ae55-a4a9cd1d4661">
<cybox:Properties xsi:type="DomainNameObj:DomainNameObjectType" type="FQDN">
<DomainNameObj:Value condition="Equals">intemet[.]work</DomainNameObj:Value>
</cybox:Properties>
</cybox:Object>
</indicator:Observable>
<indicator:Sightings sightings_count="1">
<indicator:Sighting timestamp="2018-05-01T00:00:00"/>
</indicator:Sightings>
</stix:Indicator>

我想找到一种打印域名的方法: jp-ssl.work,intemet.work

(被混淆的链接,因为它们是恶意的)使用python请求内容

EN

回答 1

Stack Overflow用户

发布于 2020-11-02 09:55:57

试试美人汤。这里的xml_data是您的输入数据

代码语言:javascript
复制
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(xml_data, 'html.parser')
>>> for tag in soup.find_all('domainnameobj:value'):
...      print(tag.text)

jp-ssl[.]work
intemet[.]work
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64638774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档