I'm doing web scraping on google maps website to get the distance between two points. the scraping is based on the className (because the attribute doesn't have an Id) so it's like :
document.getElementsByClassName("UgZKXd clearfix yYG3jf selected").item("")
is it correct to do so? does the className changes overtime? if so, any suggestions how should I implement this? I am not a frontend developer so I couldn't find the answer, thanks in advance!.
CodePudding user response:
I've been doing web scraping as a hobby for a few years now and I've automated a few tasks with selenium in WhatsApp and as far as I can tell from time to time the interface gets updated so what I do is take as a starting point some element that doesn't frequently change maybe like a frame
or a div
element that will be present in every scenario and look for the element(s) that I want from that starting point. Try to avoid using full paths because you'll have to updating your code from time to time and also avoid using CSS's class names if the framework that the page was built with uses frameworks based on components, because this ones tend to change a bit if the code gets update, which by the class name that you are showing seems to be the case.