这是我当前的代码:
url <- 'https://uws-community.symplicity.com/index.php?s=student_group'
page <- html_session(url)
get_more_info <- function(more_info, page) {
fb <- html_node(jump_to(page, more_info), xpath = '//*[@id="dnf_class_values_student_group__facebook__widget"]') %>% html_text()
}
get_table <- function(page, count) {
#find group names
name_text <- html_nodes(page,".grpl-name a") %>% html_text()
df <- data.frame(name_text, stringsAsFactors = FALSE)
#find text description
desc_text <- html_nodes(page, ".grpl-purpose") %>% html_text()
df$desc_text <- trimws(desc_text)
#find emails
# find the parent nodes with html_nodes
# then find the contact information from each parent using html_node
email_nodes<-html_nodes(page, "div.grpl-grp") %>% html_node( ".grpl-contact a") %>% html_text()
df$emails<-email_nodes
category_nodes <- html_nodes(page, "div.grpl-grp") %>% html_node(".grpl-type") %>% html_text()
df$category<-category_nodes
pic_nodes <-html_nodes(page, "div.grpl-grp") %>% html_node( ".grpl-logo img") %>% html_attr("src")
df$logo <- paste0("https://uws-community.symplicity.com/", pic_nodes)
more_info_nodes <- html_nodes(page, ".grpl-moreinfo a") %>% html_attr("href")
df$more_info <- more_info_nodes
df$fb <- lapply(df$more_info, get_more_info, page)
if(count != 44) {
return (rbind(df, get_table(page %>% follow_link(css = ".paging_nav a:last-child"), count + 1)))
} else{
return (df)
}
}
RSO_data <- get_table(page, 0)
因此,如果我删除
,这将非常有效df$fb <- lapply(df$more_info, get_more_info, page)
行,但我需要该行提供的信息。我在运行时遇到的错误是:
Error in `$<-.data.frame`(`*tmp*`, "logo", value = "https://uws-community.symplicity.com/") :
replacement has 1 row, data has 0
当我要添加的部分与使用jump_to函数的get_more_info函数有关时,为什么错误会出现在徽标刮痕线上就没有意义了。
我在这里做错了什么?我知道它与get_more_info函数有关,但我不知道需要解决什么。