Answer the question
In order to leave comments, you need to log in
How to output everything to the server after the parser?
After the page parser, it outputs in this format
Heading1
Heading2
Heading3
...
HeadingN
Only I did not understand how to output these values to the server
My code
request('https://nix-tips.ru/tag/yii2', function (err, respons, html) {
if (!err && respons.statusCode === 200){
let $ = cheerio.load(html);
$('article').each(function(i, element){
let title = $(this).find('.entry-title');
let date = $(this).find('.entry-date');
let content = $(this).find('p');
let arr = [];
while (date < 50){
arr.add(date);
}
app.get('/', function(req, res){
res.render('main', {
header: 'Новости по yii2',
date: $(date).text(),
title: $(title).text(),
content: $(content).text(),
});
});
});
} else {
console.log('Произошла ошибка!');
}
});
<div class="entry">
<h1>{{header}}</h1>
{{#if error}}
<h2>Ошибка!{{error}}</h2>
{{/if}}
<div class="body">
<ul class="people_list">
<form action="">
<select name="col" id="news">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
</select>
</form>
<div class="content">
{{#each date}}
<h2>{{this}}</h2>
{{/each}}
{{#each title}}
<p>{{this}}</p>
{{/each}}
{{#each content}}
<p>{{this}}</p>
{{/each}}
</div>
</ul>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
Something like this:
app.get('/', (req, res) => {
request('https://nix-tips.ru/tag/yii2', (err, response, html) => {
if (err || respons.statusCode !== 200) return console.log("AAAAAAAAAA", err);
let $ = cheerio.load(html);
let results = [];
$('article').each(function(i, element) {
results.push({
title : $(this).find('.entry-title'),
date : $(this).find('.entry-date'),
content : $(this).find('p')
})
});
return res.render('main', {
header : 'Новости по yii2',
results
})
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question