我正在寻找一个可以搜索和替换锚标记的 html 解析器,例如
ex
<a href="/ima/index.php">example</a>
to
<a href="http://www.example.com/ima/index.php">example</a>
更新:
我的代码与 jsoup 但不工作
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.google.common.collect.ImmutableList;
import com.google.common.net.InternetDomainName;
public class test {
public static void main(String args[]) throws IOException {
Document doc = Jsoup.connect("http://www.google.com").get();
String html =doc.outerHtml().toString();
// System.out.println(html);
Elements links = doc.select("a");
for (Element link : links) {
String href=link.attr("href");
if(href.startsWith("http://"))
{
}
else
{
html.replaceAll(href,"http://www.google.com"+href);
}
}
System.out.println(html);
}
}