Reputation: 1
I was trying rvest web scraping and i go the following error
Code
library(xml2)
library(rvest)
library(purrr)
ulr_base <- "https://journals.sagepub.com/toc/jina/33/%d"
map_df(1:4,function(i){
page <- read_html(sprintf(ulr_base,i))
data.frame(IssueID =html_text(html_nodes(page,".journalNavTitle")),
Heading = html_text(html_nodes(page,".hlFld-Title")),
Author = html_text(html_nodes(page,".entryAuthor"))
)
}) -> SageJournals
Error:
Error in data.frame(IssueID = html_text(html_nodes(page, ".journalNavTitle")), : arguments imply differing number of rows: 1, 6, 65
What should I do now. note: I use selector gadget.
Upvotes: 0
Views: 246
Reputation: 581
The issue was that you all authors were exported separately. So you had 1 issue, 6 articles, and 65 authors. With these nodes the authors are exported per article:
ulr_base <- "https://journals.sagepub.com/toc/jina/33/%d"
map_df(1:4, function(i){
page <- read_html(sprintf(ulr_base,i))
data.frame(IssueID = html_text(html_nodes(page,".journalNavTitle")),
Heading = html_text(html_nodes(page, ".heading-title")),
Author = html_text(html_nodes(page, ".all"))
)
}) -> SageJournals
Upvotes: 0