How to select different elements under a common parent element with xpath (How to select multiple tags with xpath
syntax
var rows = $x(
`//*[@id="__layout"]//li//div[
contains(@class, 'news-title')
or
contains(@class, 'news-image')
]//*[self::span or self::img]`
)
The
or
orand
inside of[]
is the key
//
means any child that is under the parent, ignore the levels
more stuff you may need for data crawling
var images = $x(`//*[@id="__layout"]//img`)
images = images.filter((image)=>{return image.width==120 && image.height==90})
const elementToDataURL = (img) => {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
context.drawImage(img, 0, 0 );
return canvas.toDataURL('image/jpeg')
}
const downloadAFile = (url) => {
const a = document.createElement('a')
a.href = url
a.target = '_blank'
a.download = url.split('/').pop() ?? '#'
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
}