I want to scrape through some product link (about 80) from a page to obtain the price value of each item.
But some items (may be 10-15% of all) are missing their price value.
My code is below:
link=page %>% html_nodes(".product-item-link") %>% html_attr("href")
get_price=function(link){
item_page=read_html(link)
item_price=item_page %>% html_nodes(".price") %>%
html_text()
return(item_price)
}
price=sapply(link,FUN=get_price,USE.NAMES=FALSE)
May I ask what code should I write/ revise if I want to show a text of "No Price Info." as a result when I loop scraping, instead of error?