R刮网-以下为“;阅读更多“;使用rvest链接并获取详细信息

R刮网-以下为“;阅读更多“;使用rvest链接并获取详细信息,r,web-scraping,rvest,R,Web Scraping,Rvest,我正在使用rvest包从网页中获取信息。我想刮网站的前两页 下面是我的代码。我面临的问题是删掉评论部分。在有“阅读更多”的地方,我想去那个链接,把所有的评论都删掉 有人能告诉我怎么做吗? 我试图跟随链接并跳转到,但没有成功 library(rvest) hospital <- html("http://www.ratemds.com/doctors/?specialty=family-gp") nxt_pg<- "&page=3" nxt_pg1<- "?page2

我正在使用rvest包从网页中获取信息。我想刮网站的前两页

下面是我的代码。我面临的问题是删掉评论部分。在有“阅读更多”的地方,我想去那个链接,把所有的评论都删掉

有人能告诉我怎么做吗? 我试图跟随链接并跳转到,但没有成功

library(rvest)

hospital <- html("http://www.ratemds.com/doctors/?specialty=family-gp")

nxt_pg<- "&page=3"
nxt_pg1<- "?page2=&"
hospital_test1 <-paste0("http://www.ratemds.com/doctors/",nxt_pg1,"?specialty=family-gp",
                        nxt_pg,sep="") 
hospital_test1 <- html(hospital_test1)

web_crawler(x=hospital)

web_crawler <- function(x)

{
  Doctor_nm <- x %>%  
    html_nodes("h2 a") %>%
    html_text()
  Doctor_nm
  # return(Doctor_nm) 

  Comments <- x %>%
    html_nodes(".rating-comment") %>%
    html_text()
  Comments
  # return(Comments)
  return(list(Doctor_nm,Comments))
}

fd<-web_crawler(x=hospital)
df <- as.data.frame(fd)
colnames(df) <- c ("Doctors_nm","Comments")
fd1<-web_crawler(x=hospital_test1)
df1 <- as.data.frame(fd1)
colnames(df1) <- c ("Doctors_nm","Comments")

Final_data <- rbind(df,df1)
库(rvest)

医院
帮助(html\U会话)
您需要处于会话上下文中才能有效地使用这些内容。@hrbrmstr我尝试过使用html\U会话,但不确定如何使用它。这就是我得到的>s另一种方法是获取与
阅读更多
相关的所有网页的列表(请参见
查看页面源代码
检查
),然后使用
html
解析这些网页。或者使用医生的姓名和ID,您可以创建唯一的url,然后相应地解析这些url。