我过去常常在网站https://unicancer.sigaps.fr/RSelenium
上进行一些网络抓取。
我想回顾一下我的团队 sigaps 积分(对于那些不知道的人,当您在科学杂志上发表文章时,您会获得积分,您获得的积分越多,您获得的认可就越多)。我想自动化,收集这些数据。
所以我已经RSelenium
在其他网站上使用过并且它有效,但是在这个特定的网站上我找不到具有这些功能的 html 标签:
remDr$findElement(using = "xpath", value = "/html/body/div[1]/div/div[2]/form/table/tbody/tr[2]/td[2]/input")$sendKeysToElement(list(username))
remDr$findElement(using = "name", value = "mdp")$sendKeysToElement(list(password))
我尝试使用 xpath 和名称标签,但两者都不起作用。我找不到任何页面元素。
我收到此错误:
Selenium message:no such element: Unable to locate element:
{"method":"xpath","selector":"/html/body/div[1]/div/div[2]/form/table/tbody/tr[2]/td[2]/input"}
(Session info: chrome=96.0.4664.45)
For documentation on this error, please visit:
https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '4.0.0-alpha-2', revision: 'f148142cf8', time: '2019-07-01T21:30:10'
System info: host: 'PD06B6F', ip: '10.208.107.111', os.name: 'Windows 10', os.arch: 'amd64',
os.version: '10.0', java.version: '1.8.0_261'
Driver info: driver.version: unknown
Error: Summary: NoSuchElement
Detail: An element could not be located on the page using the given search parameters.
class: org.openqa.selenium.NoSuchElementException
Further Details: run errorDetails method
当我使用浏览器查看页面代码时,我可以识别 html 元素:
<input name="login" class="text_box" type="text">
所以网站有问题,我需要解决RSelenium
它之间的交互问题。
这是我的全部代码(可能是 docker 问题。虽然我不是网络开发人员,但我真的不知道它是什么)
rD <- rsDriver(browser= "chrome", port = 3955L,chromever = "96.0.4664.45")
remDr <- rD[["client"]]
remDr$navigate("https://unicancer.sigaps.fr/")
remDr$screenshot(TRUE)
username <- "xyz"
password <- "lol93"
remDr$findElement(using = "xpath", value = "/html/body/div[1]/div/div[2]/form/table/tbody/tr[2]/td[2]/input")$sendKeysToElement(list(username))
remDr$findElement(using = "name", value = "mdp")$sendKeysToElement(list(password))
rD$server$stop()
remDr$close()
system("taskkill /im java.exe /f", intern=FALSE, ignore.stdout=FALSE)