1, Code:
const express = require ("express");
const superagent = require ("superagent");
const cheerio = require (" cheerio");
const app = express ();
const test = express ();
app.get ("/", (req, res,next) = > {
superagent.get("https://www.baidu.com/")
.end((err, sres) => {
if(err) {
return next(err);
}
// sres.text html cheerio.load
// jquery `$`
var $ = cheerio.load(sres.text);
var items = [];
console.log(sres.text);
res.send(items);
})
});
app.listen (3000,) = > {
console.log("app islistening at port 3000");
})
2. The result of console.log (sres.text) is as follows. Why didn"t you get the content when Baidu viewed the source code on the home page
3, < html >
< head >
<script>
location.replace(location.href.replace("https://","http://"));
</script>
< / head >
< body >
<noscript><meta http-equiv="refresh" content="0;url=http://www.baidu.com/"></noscript>
< / body >
< / html >
I hope you can give me a lesson or two and explain why. Thank you!