gpt4 book ai didi

python 报纸模块 - 从一篇文章中获取所有图像

转载 作者:行者123 更新时间:2023-12-05 07:33:16 25 4
gpt4 key购买 nike

通过使用 newspaper python模块,我可以通过以下方式从文章中获取顶部图像:

from newspaper import Article
first_article = Article(url="http://www.lemonde.fr/...", language='fr')
first_article.download()
first_article.parse()
print(first_article.top_image)

但是我需要获取文章中的所有图片。他们的 github 文档说:'All image extraction from html' is possible.但我不能只弄清楚。而且我不想手动下载 html 文件并将其保存在硬盘中,然后将文件提供给模块并获取图像。

我可以通过什么方式实现它?

最佳答案

您可能已经解决了这个问题,但是您可以通过调用 article.images 获取带有 Newspaper 的图像 url。

from newspaper import Article

article = Article(url="http://www.lemonde.fr/", language='fr')
article.download()
article.parse()
top_image = article.top_image
all_images = article.images
for image in all_images:
print(image)

https://img.lemde.fr/2020/09/22/0/3/4485/2990/220/146/30/0/a79897c_115736902-000-8pt8nc.jpg
https://img.lemde.fr/2020/09/22/0/0/5315/3543/192/0/75/0/7b90c88_645792534-pns-3418491.jpg
https://img.lemde.fr/2020/09/09/200/0/1500/999/180/0/95/0/d8099d2_51464-3185927.jpg
https://img.lemde.fr/2020/09/22/0/4/4248/2832/664/442/60/0/557e6ee_5375150-01-06.jpg

关于python 报纸模块 - 从一篇文章中获取所有图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50707496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com