Usando R para conectar Selenium-Server-Standalone
Como se refiere al postAccediendo a la API de Selenium en R En este sitio web, puedo crear un webdriver. Sin embargo, no puedo obtener los detalles del elemento como Python. ¿Puedo saber cómo hacerlo?
Me gustaría raspar la tabla de partidos de fútbol de cada ronda ...
# using R
library(RCurl)
library(RJSONIO)
library(XML)
# running selenium
system("java -jar selenium-server-standalone-2.35.0.jar")
baseURL<-"http://localhost:4444/wd/hub/"
server<-list(desiredCapabilities=list(browserName='firefox',javascriptEnabled=TRUE))
getURL(paste0(baseURL,"session"),
customrequest="POST",
httpheader=c('Content-Type'='application/json;charset=UTF-8'),
postfields=toJSON(server))
serverDetails<-fromJSON(rawToChar(getURLContent('http://localhost:4444/wd/hub/sessions',binary=TRUE)))
serverId<-serverDetails$value[[1]]$id
# navigate to 7m.cn
URL = "http://data2.7m.cn/history_Matches_Data/2009-2010/92/en/index.shtml"
getURL(paste0(baseURL,"session/",serverId,"/url"),
customrequest="POST",
httpheader=c('Content-Type'='application/json;charset=UTF-8'),
postfields=toJSON(list(url=URL)))
A continuación se muestran los códigos en Python para obtener los detalles del elemento html de 7m.cn. Además, ¿alguna mejor idea sugerir? Gracias.
# using Python
import codecs
import lxml.html as lh
from selenium import webdriver
URL = 'http://data2.7m.cn/history_Matches_Data/2009-2010/92/en/index.shtml'
browser = webdriver.Firefox()
browser.get(URL)
content = browser.page_source
browser.quit()