首页
学习
活动
专区
圈层
工具
发布

网刮Rvest
EN

Stack Overflow用户
提问于 2019-05-23 20:48:54
回答 1查看 96关注 0票数 0

我试着阅读了这篇文章的文本,但是我获得了正确的字符(0)。

代码语言:javascript
复制
 library(rvest)
 tex <- read_html("http://semanaeconomica.com/article/sectores-y-empresas/transporte/360660-renegociar-si-anular-no/")
 p_text <- tex %>%
 html_nodes("section") %>%
 html_nodes("#text") %>%
 html_text()%>%print()

我不是一个网络刮刮专家,所以我会非常感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2022-09-22 21:13:31

我已经能够使用以下代码获得页面中的文本:

代码语言:javascript
复制
library(RDCOMClient)
url <- "http://semanaeconomica.com/article/sectores-y-empresas/transporte/360660-renegociar-si-anular-no/"
IEApp <- COMCreate("InternetExplorer.Application")
IEApp[['Visible']] <- TRUE
IEApp$Navigate(url)
Sys.sleep(5)
doc <- IEApp$Document()
web_Obj <- doc$querySelector("body > div.container.se-container.se-container--sm.mb60 > div > div.se-article__body.fixed-to-pos.pl55-md.mb60 > div")
txt <- web_Obj$innerText()
txt <- strsplit(txt, "\n|\r")[[1]]
txt <- txt[txt != ""]
txt

[1] "Como una veleta que se mueve según los vientos de la indignación ciudadana, el alcalde Jorge Muñoz anunció que el Concejo Metropolitano evaluará la anulación de los contratos de Rutas de Lim... "                   
 [2] "¿QUIERE LEER LA HISTORIA COMPLETA?"                                                                                                                                                                                   
 [3] "Regístrese y obtenga 3 artículos gratis al mes y el boletín informativo."                                                                                                                                             
 [4] "Suscríbase para acceso ilimitado"                                                                                                                                                                                     
 [5] "  "                                                                                                                                                                                                                   
 [6] "   DNI  "                                                                                                                                                                                                             
 [7] "   Carnet de extranjería  "                                                                                                                                                                                           
 [8] " "                                                                                                                                                                                                                    
 [9] " "                                                                                                                                                                                                                    
[10] " "                                                                                                                                                                                                                    
[11] " "                                                                                                                                                                                                                    
[12] " "                                                                                                                                                                                                                    
[13] "  "                                                                                                                                                                                                                   
[14] "Se requiere al menos 8 caracteres, una mayúscula, una minúscula y un número"                                                                                                                                          
[15] "   "                                                                                                                                                                                                                  
[16] "   Acepto los términos y condiciones y las políticas de privacidad  "                                                                                                                                                 
[17] "Regístrese y continúe leyendo "                                                                                                                                                                                       
[18] "¿Ya tiene una cuenta? Inicie sesión "                                                                                                                                                                                 
[19] " grecaptcha.ready(function() { grecaptcha.execute('6LfO_LAZAAAAANQMr4R1KnhUFziP2QJsCQqUCHXR', {action: 'submit'}).then(function(token) { if (token) { document.getElementById('recaptcha').value = token; } }); });  "
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56282727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档