简体   繁体   English

Java使用Jsoup从HTML代码获取链接

[英]Java using Jsoup to get link from html code

so i want to store the url of this image 所以我想存储这张图片的网址

i am searching for this html code: 我正在搜索此html代码:

<link rel="image_src" href="http://ex.com/Data/CLOCK/fb.jpg">

by 通过

Elements el = doc.getElementsByAttribute("rel");
Element link = el.select("image_src").first();

the code above gives all the links in the html document which contains around 30+ links. 上面的代码给出了html文档中的所有链接,其中包含30多个链接。 is there a way to get that specific link above? 有没有办法获得上面的特定链接?

Thanks 谢谢

You can start off with a Document and work with CSS selectors: 您可以从Document开始,然后使用CSS选择器:

String selector = "link[rel=image_src][href=http://ex.com/Data/CLOCK/fb.jpg]";
Element theElement = doc.select(selector).first();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM