【问题标题】:Determining where certain text comes from on website确定某些文本在网站上的来源
【发布时间】:2016-09-16 05:46:48
【问题描述】:

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

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

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

感谢您的帮助。

【问题讨论】:

    标签: python html bash


    【解决方案1】:

    该国家地理页面的 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"
    

    【讨论】:

    • 太棒了!谢谢你。如果你不介意我问,你是怎么找到那个的?
    • @sc8ing 在 Chromium 中打开国家地理页面后,右键单击感兴趣的部分,即标题,然后选择“检查”。将打开一个包含开发人员工具的面板。然后,探索.... 在找到指向 JSON 数据的有希望的链接后,我使用 wget 下载它以验证它是否包含感兴趣的内容。
    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2012-12-03
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 2021-11-11
    • 2012-11-03
    相关资源
    最近更新 更多