簡體   English   中英

如何在報紙3k中訪問緩存的文章

[英]How to access cached articles in newspaper3k

報紙是一個很棒的圖書館,可以抓取網絡數據,但是我對文章緩存感到有些困惑。 它緩存文章以加快操作速度,但是如何訪問這些文章?

我有這樣的東西。 現在,當我使用相同的文章集兩次運行此命令時,第二次獲得返回類型None 如何訪問那些以前緩存的文章進行處理?

newspaper_articles = [Article(url) for url in links]

看着這樣的: https://github.com/codelucas/newspaper/issues/481似乎緩存方法“cache_disk”在https://github.com/codelucas/newspaper/blob/master/newspaper/utils.py可能有一個錯誤。 它確實確實將結果緩存到磁盤(搜索文件夾“ .newspaper_scraper”),但此后不加載它們。

一種解決方法是在構建報紙或使用Config類時將memoize_articles = False設置為。

newspaper.build(url, memoize_articles=False)

從源代碼檢查后,這取決於。

https://github.com/codelucas/newspaper/blob/beacce0e167349374ce0b37012b01c7c07a26890/newspaper/settings.py#L35

DATA_DIRECTORY = '.newspaper_scraper'

TOP_DIRECTORY = os.path.join(tempfile.gettempdir(), DATA_DIRECTORY)

因此,請在您的python解釋器中運行此命令以獲取緩存位置

import tempfile
tempfile.gettempdir()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM