基于班级名称的网络刮擦

发布于 2025-02-11 13:25:04 字数 246 浏览 1 评论 0原文

我正在在Google Maps网站上进行网络刮擦,以在两点之间获得距离。 刮擦基于className(因为属性没有ID),所以它是:

document.getElementsByClassName("UgZKXd clearfix yYG3jf selected").item("")

这样做正确吗? className是否会加班?如果是这样,我应该如何实施这个建议? 我不是前端开发人员,所以我找不到答案,谢谢!

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!.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮世清欢 2025-02-18 13:25:04

几年来,我一直在做网上抓取作为爱好起点某些不经常更改的元素可能会像fragediv 元素在每种情况下都存在,并寻找我想要的元素从那起点。尝试避免使用完整的路径,因为您必须不时更新代码,并且还要避免使用CSS的类名称,如果页面是使用基于组件的使用框架构建的框架代码获取更新,您正在显示的类名似乎是这种情况。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文