我已经使用
phantomjs与
RSelenium包装。有关如何设置的详细信息,请
phantomjs参见http://cran.r-project.org/web/packages/RSelenium/vignettes/RSelenium-
saucelabs.html#id2a
phantomjs,无需此处的Selenium Server详细信息即可直接进行驱动。由于它无头的性质,因此对于您概述的任务应该更快。
您的问题的第一部分可以实现如下:
appURL <- "http://web.sivicos.gov.co:8080/consultas/consultas/consreg_encabcum.jsp"library(RSelenium)pJS <- phantom()remDr <- remoteDriver(browserName = "phantom")remDr$open()remDr$navigate(appURL)# Get the third list item of the select box (MEDICAMENTOS)webElem <- remDr$findElement("css", "select[name='grupo'] option:nth-child(3)")webElem$clickElement() # select this element# Send text to input value="" name="expedientewebElem <- remDr$findElement("css", "input[name='expediente']")webElem$sendKeysToElement(list(2203))# Click the Buscar buttonremDr$findElement("id", "INPUT2")$clickElement()现在,表格已填写,单击链接。数据位于的iframe中
name="datos"。iframe需要切换为:
# switch to datos iframeremDr$switchToframe(remDr$findElement("css", "iframe[name='datos']"))remDr$findElement("css", "a")$clickElement() # click the link given in the iframe# get the resulting dataappData <- remDr$getPageSource()[[1]]# close phantom jspJS$stop()现在,iframe中的数据包含在中
appData。例如,我们使用简单的提取功能查看第三张表
readHTMLTable:
readHTMLTable(appData, which = 3)V1 V2 V3 V4 V5V61 Presentacion Comercial <NA> <NA> <NA> <NA> <NA> 2 Expediente Consec Termino Unidad / Medida Cantidad Descripcion3 000002203 01 0176 ml 60,00 FRASCO AMBAR POR 60 ML4 000002203 02 0176 ml 120,00 FRASCO AMBAR POR 120 ML5 000002203 03 0176 ml 90,00 FRASCO AMBAR POR 90 MLV7 V8 V91 <NA> <NA> <NA> 2 Fecha insc Estado Fecha Inactiv3 2007/01/30 Activo 4 2007/01/30 Activo 5 2012/03/15 Activo



