2017-10-22 1 views
1

rvest을 사용하여 테이블과 표준 HTML을 읽는 데 많은 성공을 거두었습니다. 나는 여러 개의 따옴표가있는 텍스트를 읽는 중 문제가 발생했습니다. rvest은 따옴표로 묶은 텍스트와 공백 뒤에 따옴표 붙은 텍스트의 새 줄이 나타날 때 새 문자 (a-z)를 추가하는 것으로 보입니다.이상한 인용 텍스트를 읽기 위해 rvest 사용

다음은 재현 가능한 예입니다.

library(rvest) 
read_html("https://www.lds.org/scriptures/ot/gen/1?lang=eng") %>% 
    html_node("#p3") %>% 
    html_text() 

결과 "asaid"및 "마름병"인

"3 And God asaid, Let there be blight: and there was light." 

오자이다. lol

자세한 내용을 보려면 웹 속성을 사용하여 html 구조를 살펴 보았습니다.

<p class="verse" id="p3> 
<span class="verse-number verse">3</span> 
"And God " 
"said" 
", Let there be " 
"light" 
": and there was light." 
</p> 

이렇게 형식이 잘못된 텍스트에 대한 해결책은 무엇일까 궁금합니다.

+0

여기서 문제는 두 개의 각주, 기본적으로 숨겨져 있습니다 "A"와 "B"가 있다는 것을 (. 그것을 해결하는 방법, 나는 아직도 일하고 ​​있어요 아래로 스크롤은 "각주"를 클릭합니다 그걸로. – neilfws

답변

1

"각주 표시"를 클릭 한 다음 페이지를 다시 검사하면 문제가 표시됩니다. "blight"에서 "asaid"및 "bight"의 추가 문자 "a"는 sup 태그로 싸여 숨겨진 각주의 텍스트입니다.

page <- read_html("https://www.lds.org/scriptures/ot/gen/1?lang=eng") 
page %>% 
    html_nodes(xpath = "//p[@id = 'p3']") %>% 
    html_structure() 

[[1]] 
<p#p3 .verse [data-aid]> 
    <span.verse-number.verse> 
    {text} 
    {text} 
    <a.footnote.study-note-ref [href, rel]> 
    <sup.studyNoteMarker.dontHighlight> 
     {text} 
    {text} 
    {text} 
    <a.footnote.study-note-ref [href, rel]> 
    <sup.studyNoteMarker.dontHighlight> 
     {text} 
    {text} 
    {text} 

그래서 하나 개의 솔루션은 (는 지저분한 해킹의 비트입니다) 그런 다음 sup 노드를 추출 노드 집합에서 제거하는 것입니다.

footnotes <- page %>% 
    html_nodes(xpath = "//p[@id = 'p3']//sup") 

xml_remove(footnotes) 
page %>% 
    html_nodes(xpath = "//p[@id = 'p3']") %>% 
    html_text() 

[1] "3 And God said, Let there be light: and there was light." 
관련 문제