2015-01-25 4 views
0

없이 IP를 얻을 수있는 것은 내가 아래 얻을 결과에서 "\n\t을 제거하는 방법 CasperJS 내가 CasperJS 스크립트를 업데이트 이제 한 다른 쓸모없는 데이터

var casper = require('casper').create(); 

casper.start('http://whatismyipaddress.com/', function() { 
    if (this.exists('#section_left > div:nth-child(2)')) { 
     var data = this.getElementInfo('#section_left > div:nth-child(2)'); 
     console.log(JSON.stringify(data.text)); 
    } 
}); 

casper.run(); 

아래를 참조하십시오.

"\n\n23.221.147.202\n\n\t\t\t\t\t" 

답변

0

data.text는 하나의 문자열입니다. 문자열을 문자열 화하면 공백을 이스케이프 처리하고 따옴표를 추가합니다.

console.log(data.text); 

실제로 공백을 제거 할 경우, 문자열 함수 trim()이 : : 문자열 캐릭터 라인 화하지 마십시오 이에 대한 당신의 대답은 내가 당신의 answerr을 사용

console.log(data.text.trim()); 
+0

업데이 트를하고 작동하도록 수정 내가 필요한 ----- console.log (data.text.trim()); –