-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
31 lines (27 loc) · 853 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const axios = require("axios");
const JSSoup = require("jssoup").default;
const filterNews = (news) => {
const reg = /Who|What|How|Here|This|These|Watch|quiz|\?$|\.{3,6}/;
if (!reg.test(news)) return true;
else false;
};
const gadgets_now = async () => {
let news = [];
try {
const response = await axios.get("https://techcrunch.com/");
let htmlContent = response.data; //data field has html code
//scraping..
let soup = new JSSoup(htmlContent);
let headings = soup.findAll("h2", "post-block__title");
for (let heading of headings) {
heading = heading.text;
heading = heading.replace(/\t|\n/g, ""); //remove \t and \n
if (filterNews(heading)) news.push(heading);
}
} catch (err) {
console.log(err);
if (news.length == 0) news.push("None");
}
console.log(news);
};
gadgets_now();