问题标签 [python-newspaper]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2114 浏览

python - How to input a list of URLs saved in a .txt to a Python program?

I have a list of URLs saved in a .txt file and I would like to feed them, one at a time, to a variable named url to which I apply methods from the newspaper3k python library. The program extracts the URL content, authors of the article, a summary of the text, etc, then prints the info to a new .txt file. The script works fine when you give it one URL as user input, but what should I do in order to read from a .txt with thousands of URLs?

I am only beginning with Python, as a matter of fact this is my first script, so I have tried to simply say url = (myfile.txt), but I realized this wouldn't work because I have to read the file one line at a time. So I have tried to apply read() and readlines() to it, but it wouldn't work properly because 'str' object has no attribute 'read' or 'readlines'. What should I use to read those URLs saved in a .txt file, each beginning in a new line, as the input of my simple script? Should I convert string to something else?

Extract from the code, lines 1-18:

Later I have built some functions to display the info in a desired format and save it to a new .txt. I know this is a very basic one, but I am honestly stuck... I have read other similar questions here but I couldn't properly understand or apply the suggestions. So, what is the best way to read URLs from a .txt file in order to feed them, one at a time, to the url variable, to which other methods are them applied to extract its content?

This is my first question here and I understand the forum is aimed at more experienced programmers, but I would really appreciate some help. If I need to edit or clarify something in this post, please let me know and I will correct immediately.

0 投票
0 回答
525 浏览

python - 如何使用报纸从文本文件中的 URL 列表中提取报纸文章

我正在尝试从文本文件中的多个 URL 下载/提取文章,然后想在 CSV 文件中提取相同的内容

我正在创建一个包含与特定主题相关的新闻的博客,我想使用 python 从文本文件中的一堆 URL 中提取新闻

# 我收到以下错误

我想复制这个过程,这样我就可以从数百个 URL 中提取文本。有没有办法设置它,所以我可以创建一个包含文章并提取文章的文本文件

根据我更新代码的建议更新 1 但是我仍然无法从 URL 中提取所有文章

文章

我想从 URL 列表中提取所有文章。

0 投票
1 回答
246 浏览

python - 报纸python缓存问题,每次调用相同的输出

我使用这个模块:https ://github.com/codelucas/newspaper 从https://news.bitcoin.com/下载比特币文章。但是,当我尝试从下一页“ https://news.bitcoin.com/page/2/page ”获取下一篇文章时,我得到了相同的输出。任何其他页面都一样。

我尝试过使用不同的站点和不同的起始页面。我使用的第一个链接中的文章显示在所有其他链接上。

0 投票
1 回答
1264 浏览

python - ModuleNotFoundError: No module named 'newspaper3k'

I'm attempting to install the newspaper module on python, but I keep getting an error saying that there is no such module.

I've tried making sure my directory is set to the right place, and I've checked that the module is installed. PyCharm, which I'm using, shows it to be installed when I check there. Why is it saying that there is no module when I've clearly already installed it?

0 投票
1 回答
942 浏览

python - 如何遍历 csv 行以使用 pandas 从 URLS 中提取文本

我有一堆新闻文章的 csv,我希望使用报纸 3k 包从这些文章中提取正文并将它们保存为 txt 文件。我想创建一个脚本,它遍历 csv 中的每一行,提取 URL,从 URL 中提取文本,然后将其保存为唯一命名的 txt 文件。有谁知道我该怎么做?我是一名刚接触 Python 的记者,如果这很简单,我很抱歉。

我只有下面的代码。在弄清楚如何将每个正文文本保存为 txt 文件之前,我想我应该尝试让脚本打印 csv 中每一行的文本。

0 投票
1 回答
1401 浏览

python-3.x - 图书馆:报纸(Newspaper3k)试图从新闻(来源)网站的主页解析链接

我正在尝试从使用名为Newspaper的 python 库生成的一组链接中进行解析

目标:

解析来自新闻站点主页(或特定页面,如类别)的每个链接。

问题:

  1. 尝试将“article_link”传递给“Article()”方法时,我生成了一个 AttributeError。
  2. 使用单独的代码解析来自“纽约时报”的单个链接,打印的文本不会打印整篇文章。

代码生成问题1:

错误输出:

代码生成问题2:

我还尝试了文档中示例的这种“全文”方法来打印文本:

然而,尽管整篇文章文本输出到

不会全部打印出来。原始链接、HTML 输出和打印文本输出如下所示:

链接:https ://www.nytimes.com/2019/02/26/opinion/trump-kim-vietnam.html

Html 输出:查看此 pastebin 以获取截断的输出

印刷文字:见此印刷文字不印刷整篇文章

任何帮助将非常感激。

0 投票
1 回答
39 浏览

python - 限制报纸的 URL 输出

我正在使用报纸 3 从 news.google 中提取 URL,但问题是我不断获取所有 URL(我已禁用 memoize,因为我需要完整列表)。我只想打印前 5 个链接或 5 个随机链接并不重要。我试过设置最大值,但没有奏效。有任何想法吗?

0 投票
1 回答
570 浏览

python-newspaper - 为什么我的 Newspaper3k 代码不能与 Newsweek 一起使用?

我正在使用 Jupyter Notebook 并遇到报纸问题,无法从新闻周刊中删除任何内容。我可以让它在 Goose 上运行,但我想有一个备份,以防 Goose 失败。

我尝试过其他网站,例如 Fox、Yahoo 和 CNN,所有这些都运行良好。所以 NewsWeek 是一个孤立的问题。

0 投票
1 回答
2081 浏览

python - 在 google colab 上安装 Python 报纸包的问题

我想在 google colab 上安装 python 报纸包,但它给出了一个错误。

我正在安装

0 投票
3 回答
2910 浏览

python - 如何在不下载文章的情况下使用 Newspaper3k 库?

假设我有新闻文章的本地副本。我怎样才能在这些文章上刊登报纸?根据文档,报纸库的正常使用是这样的:

就我而言,我不需要从网页下载文章,因为我已经拥有该页面的本地副本。如何在网页的本地副本上使用报纸?