2014-05-11 3 views
1

저는 JS에 완전히 익숙하며 노드 치리 오를 완전히 고수했습니다. 아무도 나를 도울 수 있다면 정말 고마워.Cheerio (node.js)가 html로 읽는 중에 오류를 반환합니다.

내가 작업하고있는 코드는 여기에 있습니다 : https://github.com/zafartahirov/bitstarter.

(수정 코드가 발견 된 후 작동하지 않는 코드는 grader.old.js라고합니다).

TypeError: Cannot call method 'utf8Slice' of null 
    at Buffer.toString (buffer.js:416:26) 
    at exports.isTag (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/utils.js:15:14) 
    at Function.filter (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/node_modules/lodash/dist/lodash.js:3150:15) 
    at /home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/api/traversing.js:9:26 
    at Function.reduce (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/node_modules/lodash/dist/lodash.js:3734:25) 
    at exports.find (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/api/traversing.js:8:17) 
    at new module.exports (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/cheerio.js:92:18) 
    at initialize (/home/ubuntu/GitHub/bitstarter/node_modules/cheerio/lib/static.js:23:12) 
    at checkHtmlFile (/home/ubuntu/GitHub/bitstarter/grader.js:59:23) 
    at Object.<anonymous> (/home/ubuntu/GitHub/bitstarter/grader.js:76:21) 
(END) 

어떤 제안 :

내가

node ./grader.js --file index.html --checks checks.json | less 

를 실행 나는 오류가 발생?

+1

은 내가 해결책을 찾은 것 같아요,하지만, 난 여전히 뭔가 이해가 안 : 'var에 cheerioHtmlFile = 기능 (htmlfile) { VAR 버퍼 = fs.readFileSync (htmlfile를); return cheerio.load (buffer.toString()); // return cheerio.load (fs.readFileSync (htmlfile)); }; ' 아직도 버퍼를 문자열로 변환해야하는 이유는 아직도 이해가 가지 않습니다. – RafazZ

+1

그럴 경우 http://www.joelonsoftware.com/articles/Unicode.html을 읽어 보시기 바랍니다. –

+0

감사합니다! 나는 분명히 할 것이다! – RafazZ

답변

4

우리는 같은 코스를 가져 가고 있으며, 디버깅하는데 꽤 시간이 걸렸습니다. cheerio.load() 메서드는 문자열이 아닌 버퍼로 간주합니다.

+0

) 어떻게 해결했는지. 나는 "더미"코드가 코멘트에 그것을 가지지 않았기 때문에 나는 혼란스러워했다. – RafazZ

+1

이전에는 Buffer 객체를 수락했지만 변경되었습니다. 나는 문제점을 열었고 필요할 경우 PR을 제출할 것이다 : https://github.com/cheeriojs/cheerio/issues/485 –