ð®ãç°¡æçãRããGoogle Books APIãå©ããŠãã¯ãã°ã«æžç±ç»é²ãã
èªãã ãè²·ã£ããããæ¬ã®èšé²ãEvernoteã«ãšã£ãŠããã®ã ãã©ããã¡ããšãããµãŒãã¹ã䜿ããããšããæ°ã«ãªã£ãŠãã¯ãã°ãéžãã ããã°ãã䜿ã£ãŠã¿ãŠæã£ãã®ã ããããŒã¯ãŒãããæ¬ãæ¢ããŠãæ¬æ£ãã«ç»é²ãããšããéçšããšãã®ãé¢åãã¡ãŸã¡ãŸå ¥åããŠãããšãããRã§ã§ããªãã ããããšããæ°ã«ãªãã
æ¢ããŠã¿ããããŸãšããŠç»é² (ISBN)ãšããæ©èœããã£ããããã䜿ãã°ISBNãããã¯ASINã³ãŒãããã©ãŒã ã«éä¿¡ããããšã§è€æ°ã®æ¬ãç»é²å¯èœã§äŸ¿å©ããã ãISBNã¯æ¬ãèŠãããã€ã³ã¿ãŒãããã§èª¿ã¹ãªããšããããªãã£ãããããé¢åã ã
ãªã®ã§ãã£ãã£ã£ãšæžç±ã®æ å ±ãæ€çŽ¢ããŠãã¯ãã°ã«ç»é²ããä»çµã¿ãå¿ èŠã«ãªã£ãããªããã°äœãããã¯ãœãšã ã®èªãã§ããã
ðš ãã£ãããš
è¡šé¡ã®éãã§
- ç»é²ãããæžç±ã®ISBNæ å ±ãGoogle Books APIã䜿ã£ãŠèª¿ã¹ã
- ãã¯ãã°ã«ãã°ã€ã³ããŠISBNããæ¬æ£ã«ç»é²ãã
Googleã®APIã䜿ããšãã¯Google Developers ConsoleããããŒãªããªããªãããšã£ãŠããã®ããäœæ³ã£ãœããã©ãä»åã¯ç°¡æçãªã®ã§ããããã®ã¯å¿ èŠãšããªããå©çšã®éã«ã¯APIã®äžéã«éããªãããã«æ³šæãå¿ èŠã
ðŠ 䜿çšããã±ãŒãž
library(jsonlite) library(purrr) library(xml2) library(rvest) library(dplyr)
Google Books API ãã察象ã®æžç±æ å ±ãååŸãã
# æ¬ã®ã¿ã€ãã«ã®äžéšãããŒã¯ãŒããçšæãã books <- c("R èšèª") # ããŒã¯ãŒããå ã«Google Books APIã§æžç±æ å ±ãæ€çŽ¢ # https://www.googleapis.com/books/v1/volumes?q=R+èšèª ãšããURLãçæãã # å¿ èŠãªå€æ°ã®ã¿éžæ # title, subtitle, authors, publisher, publishedDate, industryIdentifiers # ISBNã®ãããæžç±ãã«çµã # è€æ°ã®èè ãããå Žåããªã¹ããããã¯ãã«ã«ãã # ããŒã¿ãã¬ãŒã ã«çµæãä¿åãããindustryIdentifierså€æ°ã¯ããšã§åé€ãã # æžç±ã®é çªã¯æ€çŽ¢çµæãšçãã https://www.google.co.jp/search?q=R+èšèª df_res <- paste0("https://www.googleapis.com/books/v1/volumes?q=", strsplit(books, "[[:space:]]") %>% unlist() %>% paste(., collapse = "+")) %>% jsonlite::fromJSON(flatten = FALSE) %$% items$volumeInfo %>% dplyr::select(title, subtitle, authors, publisher, publishedDate, industryIdentifiers) %>% dplyr::filter(grepl("ISBN_10", industryIdentifiers)) %>% dplyr::mutate(authors = authors %>% purrr::map_chr(~ unlist(.) %>% paste(., collapse = ", "))) df_res %<>% dplyr::select(-industryIdentifiers) %>% dplyr::bind_cols(df_res$industryIdentifiers %>% purrr::map_df(~ dplyr::filter(., type == "ISBN_10") %>% dplyr::select(identifier)))
ãããªæãã®ããŒã¿ãã¬ãŒã ãã§ãããå šRãŠãŒã¶ãŒåŸ æã®ãRèšèªåŸ¹åºè§£èª¬ãã¯ããããä»æçºå£²ã§ãããããŸã Google Booksã«ç»é²ãããŠããªãæš¡æ§ã
- äœè : Hadley Wickham,ç³ç°åºåº,åžå·å€ªç¥,é«æ³æ äž,çŠå³¶ç倪æ
- åºç瀟/ã¡ãŒã«ãŒ: å ±ç«åºç
- çºå£²æ¥: 2016/02/10
- ã¡ãã£ã¢: åè¡æ¬
- ãã®ååãå«ãããã° (26件) ãèŠã
df_res %>% knitr::kable(format = "markdown")
title | subtitle | authors | publisher | publishedDate | identifier |
---|---|---|---|---|---|
ã¯ãããŠã®S-PLUS/Rèšèªããã°ã©ãã³ã° | 竹å ä¿åœŠ | æ ªåŒäŒç€Ÿ ãªãŒã 瀟 | 2005-11 | 4274066231 | |
RèšèªéåŒããã³ããã㯠| 2.14.1ã«å¯Ÿå¿! | ç³ç°åºåº | NA | 2012-02-03 | 4863540930 |
ãã¬ãã·ã¥ãã³ãã倧åŠé¢çãŸã§ã®ããŒã¿è§£æã»Rèšèª | NA | 枡蟺å©å€« | NA | 2005-09 | 4888488789 |
RèšèªäžçŽãã³ããã㯠| NA | èåŒå¥, ç³ç°åºåº, é«æ©åº·ä», æçåº, äºéå æ | NA | 2013 | 486354135X |
Rã«ããããŒã¿ãµã€ãšã³ã¹ | ããŒã¿è§£æã®åºç€ããææ°ææ³ãŸã§ | éæå² | 森ååºç | 2007-10 | 4627096011 |
ããã°ã©ãã³ã°R åºç€ããã°ã©ãã£ãã¯ã¹ãŸã§ | NA | é«æ©ç¥å·³ | æ ªåŒäŒç€Ÿ ãªãŒã 瀟 | 2008-11 | 4274067432 |
R&JavaScriptã«ããããŒã¿è§£æãšèŠèŠåãã¯ãã㯠| NA | Tom Barker | ç¿æ³³ç€Ÿ | 2013-11-20 | 4798136093 |
èšèªè¡çº | èšèªå²åŠãžã®äžè©Šè« | ãµãŒã«,J.R.(ãžã§ã³ã»R) | NA | 1986 | 4326198753 |
ãªãŒãããã³èšèªçè«èšç®è« II | NA | J. ãããã¯ããã, R. ã¢ãã¯ã, J. ãŠã«ãã³ | NA | 2003-08 | 4781910270 |
ç»é²ãããæžç±ã®ISBNãæ±ããã«ã¯æ¬¡ã®ããã«ãããããããã®æ¹æ³ã§è¯ãã
df_res$identifier[1]
## [1] "4274066231"
df_res %>% dplyr::filter(grepl("ç³ç°åºåº", authors)) %>% { print(.) # ãã¯ãã°ã«ç»é²ãããããISBNã®ãã¯ãã«ãä¿åããŠãã book_isbn <<- .$identifier }
## Source: local data frame [2 x 6]
##
## title subtitle
## (chr) (chr)
## 1 RèšèªéåŒããã³ããã㯠2.14.1ã«å¯Ÿå¿!
## 2 RèšèªäžçŽãã³ããã㯠NA
## authors
## (chr)
## 1 ç³ç°åºåº
## 2 èåŒå¥, ç³ç°åºåº, é«æ©åº·ä», æçåº, äºéå æ
## Variables not shown: publisher (chr), publishedDate (chr), identifier
## (chr)
ãã¯ãã°ã«ç»é²
ç¶ããŠãã¯ãã°ã«æžç±ãç»é²ããããã°ã€ã³ããå¿
èŠãããã®ã§{rvest}
ããã±ãŒãžã䜿ã£ãŠã»ãã·ã§ã³ãäœããšããããå§ããã
# ãã°ã€ã³ããã®ã»ãã·ã§ã³ session <- rvest::html_session(url = "https://booklog.jp/login")
set_values()
ã«äžããã¢ã«ãŠã³ãåãšãã¹ã¯ãŒãã¯ããããå€æŽã
# ãã°ã€ã³ã®ããããã©ãŒã ã«éä¿¡ããã¢ã«ãŠã³ããã¹ã¯ãŒããçšæ set_value <- html_form(session)[[1]] %>% set_values(account = "<ã¢ã«ãŠã³ãå>", password = "<ãã¹ã¯ãŒã>")
form_isbn <- submit_form(session, set_value) %>% jump_to("/input") %>% html_form() # ãã©ãŒã ã«å€ãæž¡ãããã®æãISBNãæ¹è¡ãããããã«ãã form_isbn[[2]]$fields[1]$isbns$value <- paste(book_isbn, collapse = "\n") submit_form(session, set_value) %>% jump_to("/input") %>% submit_form(., form_isbn[[2]]) # <session> http://booklog.jp/input # Status: 200 # Type: text/html; charset=UTF-8 # Size: 34095
ãšããããã§ð ç»é²ã§ããã
http://booklog.jp/users/uribo087
ãã§ãã ð®
ðª ææ
- ãç°¡æçããšãããã©ãã©ããç°¡æãªã®ãããããããªããAPIããŒãçšæããã®ããéåžžçããšããããšã§...
paste()
é¢æ°ã®collapseåŒæ°ãåããŠäœ¿ã£ããããª...{purrr}
ããã±ãŒãžã®äŸ¿å©ããããã£ãŠãã- APIã®ååŸçµæãé¢æ°ã«ããŠã
dplyr::arrange()
ãšããããããã¡ãã£ãšæããã