나는 다음과 같은 HTML요소를 바꾸려면 어떻게해야합니까?
<html>
<head>
<title>test</title>
</head>
<body>
<table>
<caption>table title and/or explanatory text</caption>
<thead>
<tr>
<th>header</th>
</tr>
</thead>
<tbody>
<tr>
<td id=\"test\" width=\"272\"></td>
</tr>
</tbody>
</table>
<a href=\"http://www.google.fi\" style=\"color:black\">Test link</a>
<a href=\"http://www.google.fi\"><img src=\"http://www.google.se/images/nav_logo95.png\" /></a>"
</body>
</html>;
을 그리고 나는 outerHTML에를 jsoup와 첫 번째 링크를 찾아
Element elem = page.select("a[href=" + link.getUrl() + "]:contains(" + link.getName() + ")").first();
가 난 단지 elem.html("foo")
와 내부 HTML을 대체 할 수있는 텍스트로 교체하거나 인쇄 할 elem.outerHtml()
아무도 내가 이것을 달성 할 수있는 방법을 알고 있습니까?
내가 옳지 않은 일은 잘못된 요소를 사용하는 것이 었습니다. 지금까지 올바른 요소를 선택하는 가장 좋은 방법은 모든 요소를 반복하는 것입니다. 중첩 된 루프는 여전히 정확한 루프를 찾지 못해 도움이됩니다. 예를 들면 다음과 같습니다. for (Element elem : contElems) { if (elem.id()! = "") System.out.println (elem.id()); \t 요소 contElems1 = contElems.select ("href, a [href], a [data-href], 링크 [href], a [title]"); (요소 elem1 : contElems1)에 대한 는 // (및/또는) { // 여기 코드를 삽입} I 위의 주석에 줄 바꿈을 넣어하는 방법을 알게하고 있지 않다 여기 } –
코드를 넣어 ... –