簡體   English   中英

報紙python緩存問題,每次調用都輸出相同

[英]Newspaper python cache issue, every call same output

我使用以下模塊: https : //github.com/codelucas/newspaperhttps://news.bitcoin.com/下載比特幣文章。 但是,當我嘗試從下一頁( https://news.bitcoin.com/page/2/page)獲得下一篇文章時,我得到的輸出是相同的。 其他任何頁面均相同。

我嘗試使用不同的站點和不同的起始頁。 我使用的第一個鏈接中的文章顯示在所有其他鏈接上。

import newspaper

url = 'https://news.bitcoin.com/page/2'
btc_articles = newspaper.build(url, memoize_articles = False)

for article in btc_articles.articles:
    print(article.url)

報紙圖書館會嘗試抓取整個網站,而不僅僅是您輸入的鏈接。 這意味着您不必遍歷所有頁面即可獲取文章。 但是,您可能已經注意到,lib並不能找到所有文章。

造成這種情況的原因似乎是,它不能將所有頁面都標識為類別(並且找不到供稿),請參見下文(無論頁面如何,輸出都是相同的):

import newspaper

url = 'https://news.bitcoin.com/'
btc_paper = newspaper.build(url, memoize_articles = False)

print('Categories:', [category.url for category in btc_paper.categories])
print('Feeds:', [feed.url for feed in btc_paper.feeds])

輸出:

Categories: ['https://news.bitcoin.com/page/2', 'https://news.bitcoin.com']
Feeds: []

正如您在故障報告https://github.com/codelucas/newspaper/issues/中所指出的那樣,這似乎是代碼中的錯誤(或比特幣部分上的不良網站設計,具體取決於您的看法)。 670

暫無
暫無

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

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