Extract src of <img> element (selected by class) from multiple HTML pages in node.js ?
- Yogesh Kumar
- 02-May-2022
- 0
To Extract src of <img> element (selected by class) from multiple HTML pages in node.js use the following steps:-
- Download each page in a loop with AJAX.
- Parse the DOM with something like jsdom.
- Use a selector with [
querySelectorAll()
].(https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll) to get each image element. - Use a regular expression on the image src-attribute to get the robot name. Like:
$img.src.match(/([^\/]+).png$/i)[1]
. - Download all the robots with AJAX.
- Combine robot name and downloaded robot to an object with key value pairs.
Let me know if you need more help or a code example.
195 0
7
* Be the first to Make Comment