feat: check parent element url and extract
This commit is contained in:
@@ -541,8 +541,21 @@ function scrapableHeuristics(maxCountPerPage = 50, minArea = 20000, scrolls = 3,
|
|||||||
} else if (attribute === 'innerHTML') {
|
} else if (attribute === 'innerHTML') {
|
||||||
return element.innerHTML.trim();
|
return element.innerHTML.trim();
|
||||||
} else if (attribute === 'src' || attribute === 'href') {
|
} else if (attribute === 'src' || attribute === 'href') {
|
||||||
const attrValue = element.getAttribute(attribute);
|
if (attribute === 'href' && element.tagName !== 'A') {
|
||||||
|
const parentElement = element.parentElement;
|
||||||
|
if (parentElement && parentElement.tagName === 'A') {
|
||||||
|
const parentHref = parentElement.getAttribute('href');
|
||||||
|
if (parentHref) {
|
||||||
|
try {
|
||||||
|
return new URL(parentHref, baseURL).href;
|
||||||
|
} catch (e) {
|
||||||
|
return parentHref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const attrValue = element.getAttribute(attribute);
|
||||||
const dataAttr = attrValue || element.getAttribute('data-' + attribute);
|
const dataAttr = attrValue || element.getAttribute('data-' + attribute);
|
||||||
|
|
||||||
if (!dataAttr || dataAttr.trim() === '') {
|
if (!dataAttr || dataAttr.trim() === '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user