gpt4 book ai didi

python - 确定网站上某些文本的来源

转载 作者:行者123 更新时间:2023-11-28 01:06:30 25 4
gpt4 key购买 nike

我正在尝试编写一个从 National Geographic 下载今日照片的 bash 脚本,将其设置为桌面背景,并将在页面上找到的图片的描述放在桌面上的文本文件中。 (我知道那里有执行此操作的脚本,但 NG 最近更改了他们的 POTD 页面并且它们不再有效。)

我已经下载了图片并成为桌面背景,但我对如何下载图片的完整描述感到困惑(在网站图片下方找到的那个,而不是标题中元数据中的较短版本).问题是,描述没有出现在我的脚本使用 curl(或 wget)下载的页面中。不过,在浏览器中查看时,它显然就在那里。

如果不在 html 文件中,描述文本来自哪里?如何下载/解析描述,最好使用 bash 或 python?

感谢您的帮助。

最佳答案

国家地理页面的 html 中隐藏了以下属性:

data-platform-endpoint="http://www.nationalgeographic.com/photography/photo-of-the-day/_jcr_content/.gallery.2016-09.json"

您查找的标题位于该 URL 指向的 JSON 文件中。例如,在该 JSON 文件的今天版本中,我们发现:

"caption":"<p>A giraffe leads a herd of zebras as the animals stamede from a threat unseen. Your Shot photographer Mohammed AlNaser captured this image in Tanzania\u2019s Serengeti National Park. The zebras \u201cemerged from nowhere,\u201d AlNaser writes. \u201cThey were obviously drinking water and something scared them and created a few seconds of a chaos.\u201d<\/p>\n"

关于python - 确定网站上某些文本的来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39520633/

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