使用 JSoup 仅从多个页面获取文本
我有一组 1000 个页面(链接),是通过向 Google 查询得到的。我正在使用 JSoup。我想删除图像、链接、菜单、视频等,只获取每个页面的主要文章。
我的问题是每个页面都有不同的 DOM 树,所以我不能对每个页面使用相同的命令!您知道有什么方法可以同时处理 1000 个页面吗?我想我必须使用正则表达式。也许是这样
textdoc.body().select("[id*=main]").text();//get id that contains the word main
textdoc.body().select("[class*=main]").text();//get class that contains the word main
textdoc.body().select("[id*=content]").text();//get id that contains the word content
,但我觉得我总是会错过一些东西。还有更好的想法吗?
I have a set of 1000 pages(links) that I get by putting a query to Google. I am using JSoup. I want to get rid of images, links, menus, videos, etc. and take only the main article from every page.
My problem is that every page has a different DOM tree so I cannot use the same command for every page! Do you know any way to do this for 1000 pages simultaneously? I guess that I have to use regular expressions. Something like that perhaps
textdoc.body().select("[id*=main]").text();//get id that contains the word main
textdoc.body().select("[class*=main]").text();//get class that contains the word main
textdoc.body().select("[id*=content]").text();//get id that contains the word content
But I feel that always I will miss something with this. Any better ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有不同的页面都有主文章的主类吗?
All different pages have main class for the main article?