LoginSignup
6
8

More than 5 years have passed since last update.

rvest で声優の男女データをスクレイピング #rstatsj

Last updated at Posted at 2015-05-17

こういう話がある。

しかし、この記事でスクレイピングしている声優のプロフィールページには男女のデータが載っていないようだ。

ただし、同じサイトの声優一覧ページを見るとアイコンの色により男女が判定できる。

こいつをスクレイピングして男女データを作ってみよう。

R
library(rvest)
library(pforeach)

npforeach(i=1:10, .c=rbind)({
  cat(i, "\n")
  url <- sprintf("http://lain.gr.jp/voicedb/profile/list/cid/%d", i)

  Sys.sleep(10)
  html <- html(url)

  li_nodes <- html %>% html_nodes(xpath = '/html/body/div/div/div[2]/ul/li')

  url <- li_nodes %>% html_nodes(xpath = "a") %>% html_attr("href")
  name <- li_nodes %>% html_nodes(xpath = "a") %>% html_text %>% iconv("utf8", "cp932")
  sex <- li_nodes %>% html_nodes(xpath = "img") %>% html_attr("title") %>% iconv("utf8", "cp932")

  data.frame(url=url[-(1:4)], name=name[-(1:4)], sex)
}) -> result

write.csv(result, file="voice_actors2.csv", row.names=FALSE)

結果はこちら。

url name sex
/voicedb/profile/1040 ALLANSCHINTU 男性
/voicedb/profile/3116 会一太郎 男性
/voicedb/profile/2193 相上和音 女性
/voicedb/profile/3215 相生千恵子 女性
/voicedb/profile/1003 愛川欽也 男性

Enjoy!

関連

6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8