2016-12-09 3 views
1

을 사용하여 포맷 텍스트로 stdout에 렌더링, 나는 브라우저 w3m 또는 살쾡이 같은 명령 줄에서 HTML 렌더링 의 문제에 비틀 거렸다.HTML은 CLI 구글 카드 뷰어를 구축하는 동안 루비

Nokogiri::HTML::parse(card_snippet).text

을하지만, 그것은 다음과 같이 출력한다 : 나는 텍스트을 사용하고 온 가장 가까운 노코 기리에서 뱉어

"Albert EinsteinTheoretical PhysicistAlbert Einstein was a German-born theoretical physicist. He developed the general theory of relativity, one of the two pillars of modern physics. Einstein's work is also known for its influence on the philosophy of science. WikipediaBorn: March 14, 1879, Ulm, GermanyDied: April 18, 1955, Princeton, New Jersey, United StatesInfluenced: Satyendra Nath Bose, Wolfgang Pauli, Leo Szilard, moreInfluenced by: Isaac Newton, Mahatma Gandhi, moreBooksThe World as I See It1949Relativity: The Special a...1916Ideas and Opinions2000Out of My Later Years2006The Meaning of Relativity1922The Evolution of Physics1938People also search forIsaac NewtonEduard EinsteinSonStephen HawkingElsa EinsteinSpouseMileva MarićFormer spouseThomas Edison" 

그러나 사용 살쾡이 :

cat card_snippet.html | lyx -dump -stdin

Albert Einstein 
Theoretical Physicist 
Albert Einstein was a German-born theoretical physicist. He 
developed the general theory of relativity, one of the two pillars 
of modern physics. Einstein's work is also known for its influence 
on the philosophy of science. Wikipedia 
Born: March 14, 1879, Ulm, Germany 
Died: April 18, 1955, Princeton, New Jersey, United States 
Influenced: Satyendra Nath Bose, Wolfgang Pauli, Leo 
Szilard, 

참고 : 소음을 제거한 후. 그럼에도 불구하고 라인 결말은 적절합니다.

Ruby에서 비슷한 해결책에 대한 아이디어가 있습니까? html 코드 : Pastebin Link. 말로로

+1

귀하의 질문은 적합하지 않습니다. 기본적으로 우리에게 뭔가를 권유 해달라고 요청하거나 뭔가를 쓰는 방법에 대한 의견을 제시하지만 자습서가 필요합니다. 대신, 당신이하고 싶은 것을 확인하고, 그것을 쓰고, 문제가 생겼을 때, 그 문제에 대해 특정한 질문을하십시오. "[mcve]"도 읽으십시오. 데이터 (HTML)는 문제를 설명하는 데 필요한 최소한을 사용하여 문제 자체에 있어야합니다. 링크 썩은 다음 이해가 안되는 질문의 결과, 휴식. –

+0

당신이보고있는 문제는 NodeSet에서'text'를 사용하기 때문입니다. 모든 요소를 ​​반복하고 텍스트를 개별적으로 추출해야합니다. 그러면 더 이해할 수 있습니다. –

+0

루비에서 ckmmand 시스템을 실행하여 w3m 출력을 캡쳐 할 수 있습니까? –

답변

0

이 나를 위해 작동

require 'nokogiri' 
html = `curl http://pastebin.com/raw/pYKwACBp` 
doc = Nokogiri::HTML(html) 
puts doc.text.gsub(/[\r\n]+/,"\n").strip