2013-10-31 2 views
2

저는 초보자이며 node.io를 사용하여이 페이지의 내용을 긁어 모으기 위해 할당했습니다.
http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm.JS/Node : node.io를 사용하여 태그 선택

< 이하의 텍스트 콘텐츠를 변수에있는 문자열로 저장하고 싶습니다. 이 화면이 표시되어

var nodeio = require('node.io'); var methods = { input: false, run: function() { this.getHtml(' http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm ', function(err, $) {

 //Handle any request/parsing errors 
     if (err) this.exit(err); 


     var content = $('P'); 

     this.emit(content); 
    }); 
} } 

exports.job = new nodeio.Job({timeout:10}, methods);

오류 :

내 코드는 없다 'P'를과 일치하는 요소. 제발 도와주세요 ..

답변

1

내가 너무 Error: No elements matching 'P'를 가지고 명령을 수행 할 때 :

$ ./node_modules/.bin/node.io query http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm P 

근본 원인은 현대적인 웹과 같은 그러한 잘못된 HTML에 대한 자동 보정을 지원하지 않습니다 해당 페이지에서 </P> 및 node.io을 종료 결코입니다 브라우저. <blockquote>를 조회 할 때 잘 작동하는 동안 :

$ ./node_modules/.bin/node.io query http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm blockquote 

을하지만 selenium 기술과 진정한 브라우저를 통해 HTML 문서를 구문 분석을 할 수 있습니다.

자바 스크립트는 호스트에서 셀레늄 그리드와 노드로 실행하여 원하는 것을 얻을 수 있습니다. 당신은 다른 질문에 대한 답변을 참조 할 수 있습니다 How do you get webdriverjs working? :

var webdriverjs = require('webdriverjs'); 

var client = webdriverjs.remote({ 
    host: 'localhost', 
    port: 4444, 
    desiredCapabilities: { 
    browserName: 'safari', // you can change this accordingly 
    version: '7', 
    platform: "MAC" // you can change this accordingly 
    } 
}); 

client.init(); 

client.url('http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm') 
    .getText("P",function(err, text) { console.log (text)}).call(function() {}); 

client.end(); 
+0

감사합니다 shawnzhu – Rajat