Dove
Dove

Reputation: 11

Javascript Statement for Keywords in Description Tags

Trying to extract any weather-related keywords from an og:description tag to make sure these related articles are not scrapped into a recommendation collector. Getting stuck on the return keywords; statement after my JS. It doesn't really matter if it returns a list of other keywords since these don't include weather related information anyway. Here's what I've got:

var keywords = $('meta[property="og:description"]').attr("content").split(',')
var excludes = ["storm", "storms", "tornado", "snow", "rain", "heat", "cold", "blizzard", "hurricane", "flood", "heat-wave"] 
return keywords;

I also tried something like this unsuccessfully:

var elementContent = document.querySelector('meta[property="og:description"]').content;
if (elementContent === ["storm", "storms", "tornado", "snow", "rain", "heat", "cold", "blizzard", "hurricane", "flood", "heat-wave"] > -1); { retrun 'weather' } else if (elementContent === "website"){ return 'article' }

Any help would be greatly appreciated. I am very new to this.

Upvotes: 0

Views: 45

Answers (1)

gurvinder372
gurvinder372

Reputation: 68393

Trying to extract any weather-related keywords from an og:description tag

Given that you have keywords and excludes as

var keywords = $('meta[property="og:description"]').attr("content").split(',');
var excludes = ["storm", "storms", "tornado", "snow", "rain", "heat", "cold", "blizzard", "hurricane", "flood", "heat-wave"];

filter out excludes from keywords using includes (opposite of it) as

return keywords.filter( s => !excludes.includes(s.toLowerCase()) )

Upvotes: 1

Related Questions