如何使用javascript获取HTML数据
我有一个 HTML 网页,其中充满了用类标识的 div 和 span 标签,其中包含我需要的其他格式的大量数据。我想知道使用 javascript 执行此操作的最佳方法是什么。
谢谢你的帮助。
I have an HTML web page full of divs and span tags identified with class that have lots of data I need in other format. I was wondering what would be the best way to do this with javascript.
Thank you for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最快的方法? jQuery:
The fastest way? jQuery:
更底层,但应该更快(开销更少):(
好吧,你必须做两次(一次用于 div,一次用于 span),它的代码更多,看起来不太好,但它应该还是更快)
More lowlevel, but should be a lot faster (a lot less overhead):
(ok, you'd have to do it twice (once for div and once for span), it's more code and doesn't look as nice, but it should still be faster)
如果您想要获取具有特定类的所有文档,那么您将需要测试每个对象上是否存在该类。您将需要使用
and 循环它们来检测正确的名称。
如果您找到了所需的元素,则可以对它们进行所需的操作。现在您已经处理了页面上的所有元素并找到了符合您条件的元素。祝你好运。
If you are wanting to get at all of the documents with a specific class then you will need to test for the presence of that class on each object. You will want to use a
and loop through them to detect the proper name.
If you find the elements you need do what you need with them. Now you have processed all elements on the page and found elements that match your criteria. Good luck.