gpt4 book ai didi

描述标签中关键字的 Javascript 语句

转载 作者:行者123 更新时间:2023-12-03 02:10:59 24 4
gpt4 key购买 nike

尝试从 og:description 标签中提取任何与天气相关的关键字,以确保这些相关文章不会被废弃到推荐收集器中。陷入返回关键字困境;我的 JS 之后的声明。它是否返回其他关键字列表并不重要,因为这些关键字无论如何都不包含天气相关信息。这是我得到的:

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;

我也尝试过类似的方法,但没有成功:

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' }

任何帮助将不胜感激。我对此很陌生。

最佳答案

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

鉴于您有关键字并排除为

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

使用includes(与其相反)从关键字过滤排除

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

关于描述标签中关键字的 Javascript 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49575261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com