문제

Document.getElementById를 이미 사용했지만 더 이상 작동하지 않습니다.나는 0,01 €의 가치를 얻고 싶지만 나는 할 수 없다.내 NSString *price에서 저장하고 싶지만 방법을 저장하고 싶습니다. HTML 코드는

입니다
<tr class="price">
<td>0,01</td>
<td>EUR</td>
.

나의 아이디어는

NSString *price = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('price.td').innerText;"];
.

도움이 되었습니까?

해결책

이 경우 태그 이름은 'price.td'가 아니지만 document.getElementsByTagName('id')를 실행하면 아마 원하는 것이 아닌 페이지의 모든 테이블 셀을 얻을 수 있습니다.

페이지에 jQuery가로드 된 경우 jQuery('.price td:first').text()를 사용하여 가격을 얻을 수 있습니다.

jQuery가 없으면 페이지를 제어 할 수 있습니다. 클래스를 추가 (<td class="my-price">12.44</td>)하고 document.getElementsByClassName('my-price')[0].innerHTML로 가져올 수 있습니다.

페이지를 제어하지 않고 jQuery가없는 경우 '가격'행을 찾아서 document.getElementsByClassName('my-price')[0].childNodes[0].innerHTML를 사용하여 1-ST 셀을 가져와야합니다.

다른 팁

또한 클리너 및 유연한 접근 방식은 선택기 API를 사용하는 것입니다 :

"Nofollow"> http://www.w3.org/tr/selectors-api/ko.n.>

document.querySelector('.price td:first').innerText
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top