Task 1: You will be given 10 minutes to read the text for the first time and then choose an appropriate answer for each of the following questions.
1. What’s the passage mainly about?
A. How to learn online successfully.
B. How to set up a learning goal.
C. The future of online learning.
D. The benefits of online learning.
...
var fs = require('fs');
var cheerio = require('cheerio');
var myHtml = fs.readFileSync("a.html");
var $ = cheerio.load(myHtml);
var t = $('html').find('hr');
var t2 = t.nextAll();
t2.each(function(i, elem) {
getContent($(this));
console.log($(this).text());
});
var fs = require('fs');
var cheerio = require('cheerio');
var iconv = require('iconv-lite');
var myHtml = fs.readFileSync("a.html");
var $ = cheerio.load(iconv.decode(myHtml, 'gbk'));
var t = $('html').find('hr');
var t2 = t.nextAll();
t2.each(function(i, elem) {
getContent($(this));
console.log($(this).text());
});
最终结果如下:
Task 1: You will be given 10 minutes to read the text for the first time and then
choose an appropriate answer for each of the following questions.
1. What does the “true gratitude” mean?
A. A way of life.
B. A joyous occasion.
...
function getContent(node){
var a = node.contents();
if (a.length == 0) {
if (node.is('br')){
RST+='\n';
} else {
RST+=node.text().trim();;
} else {
node.contents().each(function(i, elem){
getContent($(this));
if (node.is('p') || node.is('tr')){
RST+='\n';
}
Task 1: You will be given 10 minutes to read the text for the first time and then
choose an appropriate answer for each of the following questions.
1. What does the “true gratitude” mean?
A.A way of life.
B.A joyous occasion.
C.A much deeper level of gratitude.
D.The improvement of the quality of life.
2. Who has so many things to be grateful for?
...
看起来漂亮多了。 问题文本提取成功,接下来再提取答案文本。
1.3 提取答案文本
在html源文件中搜索answer,可以看出,答案是保存在script中的,如下:
<SCRIPT LANGUAGE="JavaScript">
var StandardAnswer = new Array()
StandardAnswer =["C","D","D","D","D"]
</SCRIPT>
var t = $('html').find('script');
var A = undefined;
t.each(function(i, elem) {
var text = $(this).text();
if (text.match('StandardAnswer')){
var a = eval(text);
console.log("standardanswer: "+ a);
A= a;
});