【问题标题】:Newspaper3k returns None summaryNewspaper3k 返回无摘要
【发布时间】:2020-01-20 09:55:45
【问题描述】:

我一直在使用 Newspaper3k 从本地存储的 html 文章中总结和生成关键字。虽然我可以成功生成关键字但不能生成摘要。 返回的摘要始终为空。

下面是我正在使用的代码

html = '''<div class="col-lg-11">\n
    <div class="entry-content e-content">\n
        <div class="img-right caption" style="width:300px"> <img alt="Plusnet" width="300" height="200" data-src="//dwkujuq9vpuly.cloudfront.net/news/wp-content/uploads/2011/01/plusnet-192701.jpg" data-sizes="auto" class="lazyload" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==">
            <noscript><img src="//dwkujuq9vpuly.cloudfront.net/news/wp-content/uploads/2011/01/plusnet-192701.jpg" alt="Plusnet" width="300" height="200"></noscript> \n
            <p>Plusnet offers broadband and home phone deals</p>\n</div>\n
        <p><strong>The Advertising Standards Authority (ASA) has upheld a complaint against PlusNet, accusing it of using misleading adverts on buses.</strong></p>\n
        <p>The ASA ruled that the BT-owned broadband service provider had misled customers into believing that they could sign up to a broadband package for £6.49 a month.</p>\n
        <p>The reality, the ASA said, was that the advertised package would cost some potential customers £12.99 a month, if they lived outside PlusNet’s low-cost area.</p>\n
        <p>It went onto add that even though PlusNet warned that the headlined price was not available to everyone, it did so in small type face on the bus advertisements, which were hard to read.</p>\n
        <p>Handing out its ruling the ASA said: ‘Small print should be clearly visible to a normally sighted person reading the marketing communication once from a reasonable distance and at a reasonable speed.</p>\n
        <p>‘We considered that the poster should have made clear that the quoted price of £6.49 for broadband was not available to all. Because the small print explaining that was illegible, we concluded that the poster was misleading.</p>\n
        <p>PlusNet was told to ensure that its smallprint on future ads were legible.</p>\n
        <h2>Which? responds</h2>\n
        <p>Ceri Stanaway, Which? broadband expert, said: ‘Its very frustrating to see a great broadband offer only to discover that you can’t get it because of where you live.</p>\n
        <p>‘Even though the PlusNet deal is available to 80% of UK households, PlusNet should have made the restrictions clearer for the 20% of households that can’t get it.</p>\n
        <p>She added: ‘Clearly, more work needs to be done by broadband providers, regulators and government to address the broadband digital divide.</p>\n
        <p><a href="/news/2011/01/cheaper-broadband-deals-for-rural-areas-242623/" title="">Cheaper broadband deals for rural areas</a></p>\n
        <p>To learn more about broadband, take a look at our Which? guide</p>\n
        <div>\n
            <h2>How to follow the latest Which? Tech news</h2>\n
            <p>Are you a <strong>Twitter</strong> user? Follow <a href="https://twitter.com/whichtech" title="" shape="rect">WhichTech on Twitter</a> for regular tech tweets.</p>\n
            <p>Prefer <strong>RSS</strong>? Don’t miss a thing with the <a href="https://www.which.co.uk/feeds/technology.xml" title="" shape="rect">Which? tech RSS feed</a>.\xa0</p>\n
            <p>For just the main headlines in <strong>newsletter</strong> form, sign-up to our weekly Which?\xa0tech email.</p>\n
            <p><a href="http://blogs.which.co.uk/technology/apple/apple-ipad-2-3g-data-plans-compared/" title="" shape="rect">Apple iPad 2 3G data plans compared</a> –\xa0find the best 3G plan for your iPad
                <br><a href="http://blogs.which.co.uk/technology/tablets-2/best-android-tablets-round-up/" title="" shape="rect">Best Android tablets round-up</a> – we look at the best iPad alternatives around
                <br><a href="https://www.which.co.uk/reviews/laptops/article/best-cheap-laptops-for-under-500" title="" shape="rect">Best cheap laptops for under £500</a> – find the best laptop deals</p>\n</div>\n </div>\n\n
    <footer class="entry-footer">\n\n \n
        <p class="entry-categories p-category">Categories:\xa0<a href="https://www.which.co.uk/news/uncategorised/" rel="category tag">Uncategorised</a></p>\n \n \n </footer>\n\n
    <div class="share share-mobile hidden-lg-up">\n <a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.which.co.uk%2Fnews%2F2011%2F01%2Fasa-raps-plusnet-243477%2F" class="share__facebook" target="_blank" title="Share ASA raps PlusNet on Facebook" data-mobileurl="https://m.facebook.com/sharer.php?u=https%3A%2F%2Fwww.which.co.uk%2Fnews%2F2011%2F01%2Fasa-raps-plusnet-243477%2F">\n\n    <span class="sr-only">Share on Facebook</span>\n  </a>\n\n <a href="https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.which.co.uk%2Fnews%2F2011%2F01%2Fasa-raps-plusnet-243477%2F&amp;text=ASA%20raps%20PlusNet" class="share__twitter" target="_blank" title="Share ASA raps PlusNet on Twitter" data-mobileurl="https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.which.co.uk%2Fnews%2F2011%2F01%2Fasa-raps-plusnet-243477%2F&amp;text=ASA raps PlusNet">\n\n    <span class="sr-only">Share on Twitter</span>\n  </a>\n\n <a href="mailto:?subject=ASA%20raps%20PlusNet&amp;body=The%20Advertising%20Standards%20Authority%20(ASA)%20has%20upheld%20a%20complaint%20against%20PlusNet,%20accusing%20it%20of%20using%20misleading%20adverts%20on%20buses.%0D%0A%0D%0Ahttps%3A%2F%2Fwww.which.co.uk%2Fnews%2F2011%2F01%2Fasa-raps-plusnet-243477%2F" title="Share ASA raps PlusNet by email" class="share__email">\n\n    <span class="sr-only">Share by email</span>\n  </a>\n</div>\n </div>
    </html>'''


article.set_html(html)
article.parse()
article.nlp()
article.keywords
article.summary






【问题讨论】:

    标签: python null summary article


    【解决方案1】:

    您是否启动了 nltk? nltk 处理摘要。

    1. 将此行添加到代码顶部: 导入nltk

    2. 在 "article.nlp()" 之前添加这一行: nltk.download('punkt')#1次下载分词器

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多