I'm using Rselenium to navigate to a webpage. The following code is doing so. I haven't provided the url because I'm using the url in a company which needs vpn to connect:
RSelenium::startServer()
require(RSelenium)
remDr <- remoteDriver()
remDr$navigate("some url")
After I navigate to the webpage, inside the html source I have the following table:
<font size="2">
<table border="1">
<tbody>
<tr>
<td> item1 </td>
<td> 0 </td>
<td> 0.05 </td>
<td> 2.43 </td>
<td align="center"> Pct </td>
<td align="center"> 1 </td>
</tr>
</tbody>
</table>
Now the question is how can I pull out the content of this table? Please assume the url is not existent, otherwise I can use an XML function: readHTMLTable(remDr$getCurrentUrl()). But this does not work for some reason. I need to use the remoteDriver handle (remDr) only. Thanks so much for your time
I prefer using rvest, so what I did was:
# Importing libraries
library(RSelenium)
library(rvest)
# Extracting table
remDr$getPageSource()[[1]] %>%
read_html() %>%
html_table()
Something like:
library(XML)
doc <- htmlParse(remDr$getPageSource()[[1]])
readHTMLTable(doc)
should allow you to access the html and process the tables contained.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With