[英]Get an URL hidden in HTML code with JSoup
I have a piece of HTML code of a web page (library thing) like: 我有一段网页(库)的HTML代码,例如:
<div class="qelcontent" id="4ed0e0ba4f1b16.47984984" style="display:block;">
<div class="description"><h4 class="first"><b>Amazon.com Product Description</b>
(<a href="https://rads.stackoverflow.com/amzn/click/com/0860783227" rel="nofollow noreferrer">ISBN 0860783227</a>, Hardcover)</h4>
I want to get the absolute URL from an href
attribute. 我想从
href
属性获取绝对URL。 I tried: 我试过了:
selector = document.select(".first .a[href]");
But it returned null
. 但是它返回
null
。 How can I get the value? 我如何获得价值?
This solves this specific problem.. not sure if it will work with your entire dataset. 这解决了这个特定的问题。不确定是否能与您的整个数据集一起使用。
String html = "<div class=\"qelcontent\" id=\"4ed0e0ba4f1b16.47984984\" style=\"display:block;\">" +
"<div class=\"description\"><h4 class=\"first\"><b>Amazon.com Product Description</b>" +
"(<a href=\"http://rads.stackoverflow.com/amzn/click/0860783227\">ISBN 0860783227</a>, Hardcover)</h4>";
Document doc = Jsoup.parse(html);
System.out.println(doc.select(".first").select("a").attr("href"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.