【发布时间】:2014-04-28 22:45:20
【问题描述】:
我有一个字符串映射,基本上我现在正在做的是获取页面正文并使用jsoup.getPageBody().split("[^a-zA-Z]+") 将其拆分为单词,然后遍历页面正文并检查我的页面中是否存在任何单词字符串映射,如下所示:
for (String word : jsoup.getPageBody().split("[^a-zA-Z]+")) {
if (wordIsInMap(word.toLowerCase()) {
//At this part word is in string of maps
}
}
当我在循环内部时,我想获得最近的超链接(href)。距离是由字数决定的。我在 jsoup 文档页面上找不到任何类似的示例。我该怎么做?
此页面的示例: http://en.wikipedia.org/wiki/2012_in_American_television
如果字符串的映射是race 和crucial 那么我想得到:
http://en.wikipedia.org/wiki/Breeders%27_Cup_Classic
http://en.wikipedia.org/wiki/Fox_Broadcasting_Company
这两个链接。
【问题讨论】:
-
您的字符串映射中的单词是什么?它们是html元素吗?它们是页面内容中的单词吗?
-
是用户给的词
-
如果你有一些示例 html,你可以展示它会让我们更容易想象我们正在谈论的内容
-
我实际上使用维基百科页面。如en.wikipedia.org/wiki/2012_in_American_television
-
所以您正试图捕获表格上最接近您给出的某个单词的链接?所以如果我给它“系统”这个词,它会返回“时代华纳有线电视”的链接。举个例子
标签: java html html-parsing jsoup href