从文件jsoup包含一些字符串到另一个字符串提取链接 [英] Extract links from document jsoup containing some string to other string

查看:488
本文介绍了从文件jsoup包含一些字符串到另一个字符串提取链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 jsoup 提取一个网站的链接。我想提取一个唯一指定的链接containg一些关键字。我要检索的链接中包含关键字下载。怎么做。我有以下code

 文档的DOC = Jsoup.parse(新URL(http://www.examplesite.com));
元件连结= doc.select(A)的第一();


解决方案

请参见这里的选择器语法。

您可以测试节点中的文本与:包含,例如元素链接= doc.select(A:含有(下载))第一(); 。如果你愿意,你可以使用:匹配的正则表达式

您获得通过 ATTR 方法,例如链接地址字符串linkaddress = link.attr(的href);

i use jsoup to extract the links from a website. i want to extract one only specified link containg some keywords. i want to retrieve the links contains the keyword "download". how to do it. i have the following code

Document doc = Jsoup.parse( new URL("http://www.examplesite.com)); 
Element link = doc.select("a").first();

解决方案

See here for the selector syntax.

You can test for the text within a node with :contains, e.g. Element link = doc.select("a:contains(Download)").first();. If you want you can use :matches for regex.

You get the link address via the attr method, e.g. String linkaddress = link.attr("href");.

这篇关于从文件jsoup包含一些字符串到另一个字符串提取链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆