youtube-comment-scraper
Version:
Scraping comments from Youtube.
126 lines (100 loc) • 2.86 kB
Markdown
[](LICENSE)
[](https://badge.fury.io/js/youtube-comment-scraper)
[](https://codeclimate.com/github/itslab-kyushu/youtube-comment-scraper)
[](http://qiita.com/jkawamoto/items/97d88f27c7d13df8dbf5)
Scraping comments from Youtube.
To install `youtube-comment-scraper` in your global environment,
```sh
$ npm install -g youtube-comment-scraper
```
after that, you can use `scraper` command.
```
Usage: scraper url [options]
url
URL for a Youtube video page or video ID.
--help, -h
Displays help information about this script
--version
Displays version info
```
Output is a JSON format text.
Its schema looks like
```json
{
"id": "the video ID.",
"channel":{
"id": "ID of the channel the video belongs to.",
"name" : "the channel name."
},
"comments": [
{
"root": "root (parent) comment body.",
"author": "author of the root comment.",
"author_id": "ID of the author",
"like": "like score (summation of +1 for like and -1 for dislike).",
"children": [
{
"comment": "reply comment.",
"author": "author of the reply comment.",
"author_id": "author ID",
"like": "like score."
},
...
]
},
...
]
}
```
Method
---------
```js
var scraper = require("youtube-comment-scraper");
```
Scraping a given Youtube page and return a set of comments.
- Args:
- url: URL of the target page or video ID.
- Returns:
Promise object. Use "then" to receive results.
Scraping a Youtube channel page and return a description of the channel.
- Args:
- id: channel ID.
- Returns:
Promise object. Use "then" method to receive results.
Cleanup this module. After all scrapings have done, this method should be called.
Otherwise, some instances of PhantomJS will keep running and it prevents
finishing main process.
```js
scraper.comments(some_url).then(function(res) {
// Printing the result.
console.log(JSON.stringify({
url: some_url,
comments: res
}));
// Close scraper.
scraper.close();
});
```
For developers
-----------------
Run the following two command.
```sh
$ npm install
$ npm run build
```
```sh
$ ./bin/cli.js <url>
```
`<url>` is a Youtube url.
License
--------
This software is released under the MIT License, see [LICENSE](LICENSE).