HTML数据提取
我正在访问一些网站,我需要提取一些数据。更具体地说 - 从这部分开始:
<input type="hidden" value="1" name="d520783895194bd08750e47c744d553d">
我需要提取“名称”部分。我听说正则表达式不是最好的解决方案,所以我想问一下访问我需要的这段数据的最佳方式是什么。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 NekoHTML 或 TagSoup 解析网站后(应该注意您的输入字段标记未关闭的事实),我建议使用 xpath 表达式:
在 groovy 中,您将以 GPath。
After parsing a website with NekoHTML or TagSoup (which should take care of the fact that your input field tag is not closed), I suggest to use a xpath expression:
In groovy you will apply it in form of GPath.
使用 Html 解析库,他们可以修复格式错误的 Html,从而可以轻松导航文档以查找和更新元素。以下是 Java/Groovy 实现列表的链接:
http://www.wavyx.net/2009/01/13/looking-for-a-java-html-parser-or-groovy/
看起来像 NekoHTML 和 TagSoup 很流行,但我没有使用过任何一个或 Groovy。但我在其他语言中使用过 Html 解析器。
Use a Html parsing library, they fix malformed Html a make it easy to navigate the document to find and update elements. Here is a link to a list of Java/Groovy implementations:
http://www.wavyx.net/2009/01/13/looking-for-a-java-html-parser-or-groovy/
Looks like NekoHTML and TagSoup are popular, but I haven't used either or Groovy for that matter. But I have used Html Parsers in other languages.