亚马逊评论使用Rvest进行搜刮

时间:2019-01-20 04:03:24

标签: r web-scraping rvest

我具有以下功能,这些功能将从Amazon应用商店中抓取应用的标题,评分和评论。我想知道是否有人可以帮助解决两个问题?

  1. date函数无法正常工作,我选择了正确的HTML节点,但是由于某种原因,它仅提供了HTML代码字符串。

  2. 我的第二个问题涉及将所有三个功能列表连接在一起。当我运行cBind函数时,它将附加列表,但是,这些列未附加到正确的记录。例如,一个非常负面的评论将附加到5星级。有没有一种方法可以正确地加入列表,以便在附加列表时,所有内容都附加到与之关联的相应记录上?

在这两个问题上的任何帮助将不胜感激!

    library(rvest)
    library(dplyr)
    library(pander)
    library(stringr)


r.date <- lapply(paste0('https://www.amazon.com/NYTimes-Breaking-Local-National-World/product-reviews/B00BOW41P8/ref=cm_cr_dp_d_show_all_btm?ie=UTF8&reviewerType=all_reviews', 0:500),
                   function(url){
                     url %>% read_html() %>% 
                       html_nodes(".review-date") %>% 
                       html_attrs() %>%
                       gsub('[\r\n\t]', '', .)

                   })


r.title <- lapply(paste0('https://www.amazon.com/NYTimes-Breaking-Local-National-World/product-reviews/B00BOW41P8/ref=cm_cr_dp_d_show_all_btm?ie=UTF8&reviewerType=all_reviews', 0:500),
                function(url){
                  url %>% read_html() %>% 
                    html_nodes(".review-title") %>% 
                    html_text() %>%
                    gsub('[\r\n\t]', '', .)

                })


r.rating <- lapply(paste0('https://www.amazon.com/NBCUniversal-Media-LLC-NBC/product-reviews/B018IOV40E/ref=cm_cr_arp_d_paging_btm_2?ie=UTF8&reviewerType=all_reviews&pageNumber=', 0:500),
                function(url){
                  url %>% read_html() %>% 
                    html_nodes(".a-icon-alt") %>% 
                    html_text() %>%
                    gsub('[\r\n\t]', '', .)

                })


r.review <- lapply(paste0('https://www.amazon.com/NYTimes-Breaking-Local-National-World/product-reviews/B00BOW41P8/ref=cm_cr_dp_d_show_all_btm?ie=UTF8&reviewerType=all_reviews', 0:500, 0:9)
               function(url){
                 url %>% read_html() %>% 
                   html_nodes(".review-text") %>% 
                   html_text() %>%
                   gsub('[\r\n\t]', '', .)

               })

Date <- unlist(r.date)
Title <- unlist(r.title)
Stars <- unlist(r.rating)
Review <- unlist(r.review)

DF <- as.data.frame(Cbind(Date,Stars,Title,Review))

0 个答案:

没有答案
相关问题