如何通过编程对Hacker News故事进行投票?

0 投票
1 回答
628 浏览
提问于 2025-04-15 21:59

我决定写一个类似于这个网站的应用:http://michaelgrinich.com/hackernews/,但是是为了安卓设备。我打算使用一个网页应用的后台(因为我更喜欢用Python和网页编程,而不是完全用Java为安卓设备编写)。

目前我实现的功能大概是这样的:

$ 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

之后这个安卓应用会使用这个API。

有没有人有关于如何程序化浏览Hacker News的经验?

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

撰写回答