首页 > > > [R爬虫]亚马逊Kindle热销榜价格排序
#参考了http://www.cnblogs.com/weibaar/p/4824578.html的思路
#代码目的是发现亚马逊Kindle热销榜中5元以下书籍都有哪些
#槽点:中国顾客对价格这么敏感亚马逊同学居然没有直接对价格筛选的功能...
#不然原作者应该不会整这个案例
library(stringr)
library(rvest)
data.frame()->alldata
url="https://www.amazon.cn/gp/movers-and-shakers/digital-text/#"
for(i in 1:5)
{
page=str_c(url,i)
read_html(page)->website
html_nodes(website,"div.zg_itemRow div div div a div") %>% html_text()->book
gsub("\n","",book)->book
str_trim(book)->book
html_nodes(website,"div.zg_itemRow div div div div.a-row span span") %>% html_text()->price
gsub("¥","",price)->price
cbind(book,price)->bp
rbind(alldata,bp)->alldata
Sys.sleep(2) #听说太快了会被封IP所以要手动加延迟
}
alldata$price=as.numeric(alldata$price)
alldata[alldata$price<5,]->newdata
newdata[order(newdata$book),]
newdata[order(newdata$price),]原文作者:;如有侵权,请联系管理员删除。