일부 text
이 <html>
태그 외부에있는 문서로 작업하고 있습니다. 본문 안의 데이터를 읽을 때 html 태그에도없는 텍스트를 반환합니다.xpath가 html 태그 외부로 텍스트를 반환하는 이유는 무엇입니까?
page_text = Nokogiri::HTML(open(file_path)).xpath("//body").text
p page_text
출력 :이
"WARC/1.0\nWARC-Type: response\nWARC-Date: 2012-02-11T04:48:01Z\nWARC-TREC-ID: clueweb12-0000tw-13-04988\nWARC-IP-Address: 184.85.26.15\nWARC-Payload-Digest: sha1:PNCB5NNAA766RLLISZ6ODV3FJZBCATKR\nWARC-Target-URI: http://www.allchocolate.com/health/basics/\nWARC-Record-ID: \nContent-Type: application/http; msgtype=response\nContent-Length: 14577\n\n\n\n\n sample document\n\n\n hello world\n\n"
문서 :
WARC/1.0
WARC-Type: response
WARC-Date: 2012-02-11T04:48:01Z
WARC-TREC-ID: clueweb12-0000tw-13-04988
WARC-IP-Address: 184.85.26.15
WARC-Payload-Digest: sha1:PNCB5NNAA766RLLISZ6ODV3FJZBCATKR
WARC-Target-URI: http://www.allchocolate.com/health/basics/
WARC-Record-ID: <urn:uuid:ff32c863-5066-4f51-802a-f31d4af074d5>
Content-Type: application/http; msgtype=response
Content-Length: 14577
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>sample document</title>
</head>
<body>
hello world
</body>
</html>
"[mcve]"을 (를) 읽으십시오. 이미지를 사용하여 예상 출력을 표시하지 마십시오. 링크 썩어 다음 휴식 시간에 귀하의 질문을 이해하지 않습니다. 대신 정보를 질문에 복사하여 붙여넣고 가독성을 위해 적절하게 형식을 지정하십시오. Nokogiri로 전달하기 전에 원본에서 HTML이 아닌 부분을 제거해야합니다. 헤더 정보가 무엇인지 모르기 때문에 혼란 스러울뿐입니다. –
@ theTinMan 제안 해 주셔서 감사합니다. 제 질문을 수정했습니다. – Abdullah