0
我想使用RSelenium刮这个网站link。我成功地抓取了网页上的大部分内容,但正试图进行“设施访问”和“设施投诉”。由于这两个按钮在使用开发人员工具检查它们时都具有javascript href,因此我一直使用phantomjs和RSelenium。RSelenium抛出StaleElementReference错误
我可以成功地通过幻影浏览网页,但每当我试图提取使用$用getElementText领域的文字,我抛出了以下错误:
Selenium message:{"errorMessage":"Element does not exist in cache","request":{"headers":{"Accept":"application/json, text/xml, application/xml, */*","Accept-Encoding":"gzip, deflate","Host":"localhost:4444","User-Agent":"libcurl/7.53.1 r-curl/2.6 httr/1.2.1"},"httpVersion":"1.1","method":"GET","url":"/attribute/id","urlParsed":{"anchor":"","query":"","file":"id","directory":"/attribute/","path":"/attribute/id","relative":"/attribute/id","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/attribute/id","queryKey":{},"chunks":["attribute","id"]},"urlOriginal":"/session/c0f30500-55d0-11e7-96dd-3b147ee40d88/element/:wdc:1497974074536/attribute/id"}}
Show Traceback
Error: Summary: StaleElementReference Detail: An element command failed because the referenced element is no longer attached to the DOM. class: org.openqa.selenium.StaleElementReferenceException Further Details: run errorDetails method
,当我使用$ CURRENTURL和$ screenship(display = T)显示正确的网站呈现和正确的链接。
我知道它是与如何元素附加到DOM,但我不知道如何解决这个问题中的R下面
代码:
url <- "https://dhs.arkansas.gov/dccece/cclas/FacilityInformation.aspx?FacilityNumber=23516"
rd<-remoteDriver(browserName = 'phantomjs')
rd$open()
rd$navigate(url)
webElem<- rd$findElement(using="xpath", value = '//*[@id="ctl00_ContentPlaceHolder1_lbtnVisits"]')
webElem$clickElement()
webElem$findElements('css',"#aspnetForm > div.page > div.main")
webElem$getElementAttribute("id")