fix: scraper fails when result has domain w/o www

When user adds a domain with www and the google search result has the domain without www, the scraper fails.
This commit is contained in:
Towfiq
2022-12-01 22:15:47 +06:00
parent 8c8064f222
commit 6d7cfec953

View File

@@ -173,7 +173,7 @@ export const getSerp = (domain:string, result:SearchResult[]) : SERPObject => {
if (result.length === 0 || !domain) { return { postion: false, url: '' }; }
const foundItem = result.find((item) => {
const itemDomain = item.url.replace('www.', '').match(/^(?:https?:)?(?:\/\/)?([^/?]+)/i);
return itemDomain && itemDomain.includes(domain);
return itemDomain && itemDomain.includes(domain.replace('www.', ''));
});
return { postion: foundItem ? foundItem.position : 0, url: foundItem && foundItem.url ? foundItem.url : '' };
};