用于从hackernews检索评论和故事的python库
hackernews_scraper的Python项目详细描述
哈克内斯刮刀
==================
抓取[黑客新闻](https://news.ycombinator.com)评论和帖子
使用[Algolia API](http://hn.algolia.com/api/)。
用法
=====
``Python
来自hackernews scraper import commentscraper
commentscraper.getcomments(自=1394039447起)
```
以上命令将返回一个生成器,该生成器将一次生成一条评论。
它将继续运行,直到没有更多的评论可供获取,或者直到
它达到了Hacker News设置的50页限制。在后一种情况下,a
将引发“Toomanyitemsexception”。
如果hacker news api响应缺少任何必需字段,则scraper
将引发“keyerror”。
响应格式
===============
评论:
```
{
“作者”:u'dhmholley',
“注释ID”:u'7531026',
“评论文”:你还在吹哨吗?…',
“创建位置”:U'2014-04-04T12:57:38.000Z',
“父ID”:7530853,
“点”:1,
“故事ID”:无,
“故事标题”:无,
“故事URL”:无,
“时间戳”:1396616258,
“标题”:无,
“url”:无
}
```
故事:
```
{
“作者”:u“sethco”,
“创建位置”:U'2014-04-04T12:56:23.000Z',
“objectid”:无,
“点”:1,
“故事文本”:1,
“时间戳”:1396616183,
“标题”:今日美国电力公司IPO,
“url”:u'http://www.businesswire.com/news/home/20140403006541/en.uz4cbq1dvih'
}
```
测试
=======
您需要有[httpretty](https://github.com/gabrielfalcao/httpretty)
和[工厂男孩](https://github.com/rbarrois/factory\u boy)已安装。
在根文件夹或“tests”文件夹中运行“notests”。
==================
抓取[黑客新闻](https://news.ycombinator.com)评论和帖子
使用[Algolia API](http://hn.algolia.com/api/)。
用法
=====
``Python
来自hackernews scraper import commentscraper
commentscraper.getcomments(自=1394039447起)
```
以上命令将返回一个生成器,该生成器将一次生成一条评论。
它将继续运行,直到没有更多的评论可供获取,或者直到
它达到了Hacker News设置的50页限制。在后一种情况下,a
将引发“Toomanyitemsexception”。
如果hacker news api响应缺少任何必需字段,则scraper
将引发“keyerror”。
响应格式
===============
评论:
```
{
“作者”:u'dhmholley',
“注释ID”:u'7531026',
“评论文”:你还在吹哨吗?…',
“创建位置”:U'2014-04-04T12:57:38.000Z',
“父ID”:7530853,
“点”:1,
“故事ID”:无,
“故事标题”:无,
“故事URL”:无,
“时间戳”:1396616258,
“标题”:无,
“url”:无
}
```
故事:
```
{
“作者”:u“sethco”,
“创建位置”:U'2014-04-04T12:56:23.000Z',
“objectid”:无,
“点”:1,
“故事文本”:1,
“时间戳”:1396616183,
“标题”:今日美国电力公司IPO,
“url”:u'http://www.businesswire.com/news/home/20140403006541/en.uz4cbq1dvih'
}
```
测试
=======
您需要有[httpretty](https://github.com/gabrielfalcao/httpretty)
和[工厂男孩](https://github.com/rbarrois/factory\u boy)已安装。
在根文件夹或“tests”文件夹中运行“notests”。