I have used the Axios library to fetch the metadata from the URL.
export default class HsLinkLoder {
private static _instance: HsLinkLoder;
private constructor() {
}
public static getInstance(): HsLinkLoder {
// Do you need arguments? Make it a regular static method instead.
return this._instance || (this._instance = new HsLinkLoder());
}
public async lodeLink(url:string){
await axios.get(url,{
}).then(r=>{
this.getMetaContent(r.data,"description")
console.log(r.data.filter('meta'))
console.log(JSON.stringify(r.data))
}).catch(e=>{
console.log(JSON.stringify(e))
})
}
public getMetaContent(html:Document , name:string) {
console.log(html.getElementsByTagName(name));
}
}
I tried to read Meta using this function posted on this question
public getMetaContent(html:any, name:string) {
return html.filter((index:any, tag:any) => tag && tag.name && tag.name == name).attr('content');
}
But it's not working. I am getting an empty response.
How to use this function with the Axios?