- 论坛徽章:
- 2
|
本帖最后由 OwnWaterloo 于 2013-06-27 07:26 编辑
一直抱有侥幸心理: google reader 关闭会不会是一个愚人节玩笑。。。 马上就要7月了,看来是没希望了。。。
这年头google也不靠谱了。。。 赶紧备份吧。。。
- history
google reader相对于其他阅读器的牛x之处在于它有rss的历史。。。 不知道有没有类似的替代方案。。。 如果有的话,下面算是白折腾了。。。
- url scheme
对没有公开url scheme的网站,自己去猜简直就是坑。。。 google了一下,搜到两个比较有用的信息:
i) authentication http://stackoverflow.com/questio ... der-of-a-given-feed
http://www.google.com/reader/atom/feed/URL 需要认证。。。 那写http-client就会比较麻烦。。。
http://www.google.com/reader/public/atom/feed/URL 就不需要了。。。
ii) gr:continuation https://adityanag.com/journal/20 ... -archive-of-a-site/
从 http://www.google.com/reader/public/atom/feed/URL?n=COUNT 可以得到 COUNT 条 entry 。经测试 COUNT 默认为 20, 最大为 1000 。
如果返回的xml里有 gr:continuation 节点, 它的内容就可以用于继续下载。
- # 最新 20 条
- $ curl -sL 'http://www.google.com/reader/public/atom/feed/http%3A%2F%2Fokmij.org%2Fftp%2Frss.xml' | egrep -o '<gr:continuation>([^<]*)</gr:continuation>'
- <gr:continuation>CL2K65mn-bMC</gr:continuation>
- # 使用 c=CL2K65mn-bMC 就可以从 20 条之后继续下载, n=30 选择后续 30条
- $ curl -sL 'http://www.google.com/reader/public/atom/feed/http%3A%2F%2Fokmij.org%2Fftp%2Frss.xml?c=CL2K65mn-bMC&n=30' | egrep -o '<gr:continuation>([^<]*)</gr:continuation>'
- <gr:continuation>CLnN5sGQhK4C</gr:continuation>
- # CLnN5sGQhK4C 又可用于 50 条之后的查询
复制代码 当返回的xml里没有 gr:continuation 节点时就到末尾了。
- atom-continuation-download
于是写了个下载的脚本。。。 依赖bash(需要--enable-cond-regexp (info "(bash) Optional Features" )), curl, tail, date(其实没什么必要), mkdir.
使用方法:
- # 下载 http://okmij.org/ftp/rss.xml 的所有历史
- $ atom-continuation-download http%3A%2F%2Fokmij.org%2Fftp%2Frss.xml
- # 每次获取 326 条
- $ atom-continuation-download http%3A%2F%2Fokmij.org%2Fftp%2Frss.xml 326
- # 传递一些参数给 curl
- $ CURL_OPTIONS='--socks5 localhost:1080 --silent' atom-continuation-download http%3A%2F%2Fokmij.org%2Fftp%2Frss.xml
复制代码 代码:
- #!/bin/bash
- count="${2:-1212}"
- rss="${1:-http%3A%2F%2Fokmij.org%2Fftp%2Frss.xml}"
- continuation="${rss}.continuation.txt"
- prev="${3:-$(tail -n 1 "$continuation" 2>/dev/null)}"
- if [ -z "$prev" ]; then
- atom="${rss}-$(date +'%Y%m%d%H%M').xml"
- url="http://www.google.com/reader/public/atom/feed/${rss}?n=${count}"
- else
- mkdir -p "$rss"
- atom="${rss}/${prev}.xml"
- url="http://www.google.com/reader/public/atom/feed/${rss}?n=${count}&c=${prev}"
- fi
- echo "$url"
- if [[ "$(curl $CURL_OPTIONS -L "$url" | tee "$atom" )" =~ $(echo '<gr:continuation>([^<]*)</gr:continuation>') ]]
- then
- next="${BASH_REMATCH[1]}"
- echo "$next" >> "$continuation"
- exec "$0" "$rss" "$counts" "$next"
- fi
复制代码 - urlencode
atom-continuation-download 不负责 urlencode , 要求传递给它的 url 必须是 encoded 。 (其实原始的 url 传递给 curl 也是可以的, 只是创建文件名会比较麻烦)。
urlencode这工作说容易也容易, python, perl, php, ... 都可以做。 难的地方是: 使用环境上有python/perl... 吗?
是在代码里使用其中一种(比如python), 然后在只有perl的机器上重写相关的部分?
还是在代码里将所知道的方法都写上,然后在目标机器上进行测试? 怎么让我想起了万恶的 ./configure 。。。
于是没有将urlencode写在download的代码里。 而是单独用 curl + nc + tail 写了一个。。。用法:
- $ urlencode 'http://www.4clojure.com/problems/rss'
- http%3A%2F%2Fwww.4clojure.com%2Fproblems%2Frss
- $ atom-continuation-download $(urlencode 'http://www.4clojure.com/problems/rss')
复制代码 代码:
- #!/bin/sh
- nc -l "${URLENCODE_PORT:-1212}" | tail -n 1 &
- curl --silent --max-time 1 --data-urlencode "${1:-http://okmij.org/ftp/rss.xml}" "localhost:${URLENCODE_PORT:-1212}"
复制代码 - future
长久之计?
选择一个google reader的替代品? 没仔细留意, 不过得到的消息都是新选择的阅读器不支持历史。。。
自己从现在开始为rss在本地记录历史? 那这两天来不及发现的好站的历史可能就没了。。。 看google reader是只关闭web界面还是连api一起给关了。。。
还是说不通过rss, 对喜欢的网站直接web scraping。。。 不过弄好了自己没时间看也是个问题啊。。。
总之。。。 暂时先把数据抓到本地再说。。。 否则可能就来不及了。。。
|
|