Я новичок в Rselenium.Я пытаюсь очистить все отзывы с сайта ниже.
https://www.google.com/search?client=firefox-b-1-ab&ei=fthAXLWfC8qp_QavqbGIDQ&q=fox+volkswagen+rochester+hills&oq=&gs_l=psy-ab.3.5.35i39l6.24734.25762..29755...1.0..0.114.114.0j1......0....1..gws-wiz.....6..0i71j0j0i131.7sWXKnj597Y#lrd=0x8824e9cf8f68257b:0xc45f1982878cfc94,1,,,
Моя проблема в том, что я могу очистить только 10 отзывов из 370. Я думаю, что мой прокручиваемый код не работает правильно, чтобы очиститьвсе отзывы.Я пробовал несколько способов заставить его работать, но ни один из них не работает.
#simulate scroll down for several times
count=read_html(pagesource) %>%
html_nodes(".p13zmc") %>%
html_text()
#Stores the number of reviews for the url to know how many times to scroll down
#This part of the code does not work fine
scroll_down_times=count %>%
str_sub(1,nchar(count)-5) %>%
as.numeric()
for(i in 1 :scroll_down_times){
webEle$sendKeysToActiveElement(sendKeys = list(key="page_down"))
#the content needs time to load,wait 1.2 second every 5 scroll downs
if(i%%5==0){
Sys.sleep(1.2)
Кроме того, я попытался реализовать executeScript
, все еще не работает
# Keep scrolling down page, loading new content each time.
last_height = 0 #
repeat {
remDr$executeScript("window.scrollTo(0,document.body.scrollHeight);")
Sys.sleep(3) #delay by 3sec to give chance to load.
# Updated if statement which breaks if we can't scroll further
new_height = remDr$executeScript("return document.body.scrollHeight")
if(unlist(last_height) == unlist(new_height)) {
break
} else {
last_height = new_height
}
}
Я делаюне понимаю, как это сделать.Любые предложения и помощь будут оценены.Заранее спасибо.