TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Welcome to Earth View

2 点作者 rolux将近 10 年前

1 comment

rolux将近 10 年前
Didn&#x27;t find the &quot;Download All&quot; option... but this should do:<p><pre><code> import json import os import re import requests url = &#x27;https:&#x2F;&#x2F;earthview.withgoogle.com&#x2F;%s&#x27; def get_data(slug=None): if not slug: html = read_url(url % &#x27;&#x27;) slug = re.search(&#x27;href=&quot;&#x2F;(.*?)&quot;&gt;Explore&lt;&#x2F;a&gt;&#x27;, html).group(1) html = read_url(url % slug) data = json.loads( re.search(&#x27;data-photo=&quot;(.*?)&quot;&#x27;, html).group(1).replace(&#x27;&amp;#34;&#x27;, &#x27;&quot;&#x27;) ) write_json(&#x27;..&#x2F;json&#x2F;%s.json&#x27; % slug, data) jpg = read_url(data[&#x27;photoUrl&#x27;], binary=True) write_image(&#x27;..&#x2F;jpg&#x2F;%s.jpg&#x27; % slug, jpg) get_data(data[&#x27;nextUrl&#x27;][1:]) def read_url(url, binary=False): print(&#x27;reading&#x27;, url) r = requests.get(url) return r.content if binary else r.text def write_image(path, data): if not os.path.exists(path): print(&#x27;writing&#x27;, path) with open(path, &#x27;wb&#x27;) as f: f.write(data) def write_json(path, data): if not os.path.exists(path): print(&#x27;writing&#x27;, path) with open(path, &#x27;w&#x27;) as f: f.write(json.dumps(data, indent=4, sort_keys=True)) if __name__ == &#x27;__main__&#x27;: get_data()</code></pre>