1.I created a node file that will scrape the provided url: https://www.billboard
ID: 3714888 • Letter: 1
Question
1.I created a node file that will scrape the provided url: https://www.billboard.com/charts/rap-song and send an email of all artists that are sung. However for some reason it's not sending any email.
This is my code-
var express require ('express'); var requestrequire('request') var cheeriorequire('cheerio'); var nodemailerrequire('nodemailer') var fs var app -require('fs'); - express); var transporter nodemailer.createTransport( service: Gmail' auth: user: 'me@gmail.com pass: '123name app.get('/scrape, function(req, res) var $, scraped_data, url; url "https://www.billboard.com/charts/rap-song" // Send a request to the URL we want to scrape // and return the data request (url, function(error, response, html) // Assuming there is no error if(error && response. StatusCode = 200) { // jQuery'ify the returned HTML cheerio. load(html); // like checking if a number is lower than // it was yesterday scraped_data $('a.chart-row artist').text) var mailoptions from: 'me@gmail.com to: 'ma@gmail.com, subject: 'YOUR_SUBJECT, text: 'YOUR_MESSAGE' scraped_data t; // send mail with defined transport object transporter.sendMail (mailOptions, function(error, info) if(error) return console.log(error); console.log( 'Message sent: 'info.response);Explanation / Answer
Can you please provide the error output that you are getting.
*Maybe you forgot to start the server :
you can solve it by keeping this code at the bottom : app.listen(4000);
*Make sure that from mail address and send mail address are valid and also check that password is valid
*Make sure you have installed all the required dependencies
Following is the code that I have tested And it is able to scrap and send the mail.
var express = require('express');
var request = require('request');
var cheerio = require('cheerio');
var nodemailer = require('nodemailer');
var fs = require('fs');
var app = express();
var transporter = nodemailer.createTransport({
service:'Please put your service name here',
auth:{
user:'your from mail ',
pass:'Your from mail Password should here'
}
});
app.get('/scrape',function(req,res){
var $,scraped_data, url;
url = 'https://www.billboard.com/charts/rap-song';
request(url, function(error, response, html){
if(!error && response.statusCode == 200){
$ = cheerio.load(html);
scraped_data = $('a.chart-row__artist').text();
var mailOptions = {
from:'the same mail that you have given in transporter object',
to :'your receiver mail',
subject: 'Let it can be any subject',
text:'List of artists '+ scraped_data
};
transporter.sendMail(mailOptions,function(error,info){
if(error){
console.log(error);
return ;
}
console.log('message send'+info.response);
})
}
})
})
app.listen(4000);
//open your browser and go to the url : localhost:4000/scrape
Now it will should and send the mail
Thank you and upvote my answer if found it useful
Comment here if you have any queries
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.