在HTML标头之后打印“ p”标签的内容

时间:2019-03-12 14:08:52

标签: python html scraper

我正在尝试完成数据收集器分配。除最后一部分外,所有其他工作均有效,在该部分中,我需要根据用户搜索条件打印报告给网站的网络安全漏洞的描述。

for index in range(2): 
    response = requests.get(url_values[index])
    content = response.content
    soup = BeautifulSoup(content,"lxml")
    #find the table content
    for header in soup.find_all("h3", string = "Description"):
        text = find_next.("p")
        print (text)

这是我要从中获取信息的区域中的HTML外观:

 ...<section class="content-band">              
        <div class="content">



            <h3>Risk</h3>                           

            <div><p>Low</p></div>






            <h3>Date Discovered</h3>
            <p>February 12, 2019</p>




            <h3>Description</h3>
            <p>Microsoft Windows is prone to a local information-disclosure 
             vulnerability.                                                                        

            Local attackers can exploit this issue to obtain sensitive 
            information that may lead to further attacks.</p>




            <h3>Technologies Affected</h3>...

我想要“ Description”标头(是h3元素)的内容(在p元素中)。我已经尝试了类似的“ find_next_sibling”,似乎无法正常工作。

任何建议都值得赞赏。

1 个答案:

答案 0 :(得分:1)

您可以从app.use(morgan(':method :url HTTP/:http-version', { stream: winston.stream }));兄弟元素中获取文本,如下所示:

h3