我决定编写一个类似于:http://michaelgrinich.com/hackernews/的应用程序,但对于Android设备,我的想法将使用Web应用程序后端(因为我宁愿使用Python和Web进行编码,而不是完全使用Java设备进行编码)。 / p>
我现在所实现的是这样的:
$ curl -i http://localhost:8080/stories.json?page=1\&stories=1
HTTP/1.0 200 OK
Date: Sun, 25 Apr 2010 07:59:37 GMT
Server: WSGIServer/0.1 Python/2.6.5
Content-Length: 296
Content-Type: application/json
[{"title": "Don\u2019t talk to aliens, warns Stephen Hawking", "url": "http://www.timesonline.co.uk/tol/news/science/space/article7107207.ece?", "unix_time": 1272175177, "comments": 15, "score": 38, "user": "chaostheory", "position": 1, "human_time": "Sun Apr 25 01:59:37 2010", "id": "1292241"}]
下一步(最后我认为)是投票,我的设计是这样做的:
$ curl -i http://localhost:8080/stories/1 -d "vote=up" -u username:password
将投票并且:
$ curl -i http://localhost:8080/stories/1 -d "vote=down" -u username:password
投票。
我不知道怎么做...虽然我打算使用Twill,但登录链接总是不同的,例如:
http://news.ycombinator.com/x?fnid=7u89ccHKln
稍后Android应用将使用此API。
以编程方式浏览黑客新闻的任何经验?
答案 0 :(得分:3)
我是http://michaelgrinich.com/hackernews/的开发者。
这是所有在设备上发生的黑魔法,直接从news.yc抓取HTML。想弄清楚有点棘手,但并不是那么糟糕。只是一些聪明和cookie管理。
我决定不使用后端服务器有几个原因,最大的一个是安全性。我确信用户不希望他们的身份验证凭据通过第三方传递 - 特别是HN周围的人。
答案 1 :(得分:2)
Twill可以列出所有链接,并将链接作为对象获取:
login_url = ''
for link in showlinks():
if link.text == "login":
login_url = link.url
go(login_url)
所以链接类似于:http://news.ycombinator.com/x?fnid=SvdNlGQoqo