Android Story

[ Android ] WebView에서 나오는 html Jsoup으로 파싱하기

WhiteDuck 2016. 9. 23. 18:25

[ Android ] WebView에서 나오는 html Jsoup으로 파싱하기



Dropbox 인증코드를 가져오는데 있어서 WebView를 통해 구현하려다 redirect_uri에서 막혀 버렸다. Menifast에서 intent-filter를 가지고 <data  (host, schema) />를 추가해보아도 어찌 사용하는지 잘 모르겠다.


 그래서 저자는 WebView에서 나오는 html을 파싱해서 데이터를 얻어내고자 하였다.


1) onCreateView() // 저자는 Fragment에 WebView를 사용하였다.




2) JavaScriptInterface class



3) Handler // 다른 곳으로 메시지를 보내기 위해 사용하였다.




=============================================================


Jsoup 라이브러리 

http://jsoup.org/download


select 메서드에서 찾고자 하는 값의 위치를 입력한다.

PatternMatchesExample
*any element*
tagelements with the given tag namediv
ns|Eelements of type E in the namespace nsfb|name finds <fb:name>elements
#idelements with attribute ID of "id"div#wrap#logo
.classelements with a class name of "class"div.left.result
[attr]elements with an attribute named "attr" (with any value)a[href][title]
[^attrPrefix]elements with an attribute name starting with "attrPrefix". Use to find elements with HTML5 datasets[^data-]div[^data-]
[attr=val]elements with an attribute named "attr", and value equal to "val"img[width=500]a[rel=nofollow]
[attr^=valPrefix]elements with an attribute named "attr", and value starting with "valPrefix"a[href^=http:]
[attr$=valSuffix]elements with an attribute named "attr", and value ending with "valSuffix"img[src$=.png]
[attr*=valContaining]elements with an attribute named "attr", and value containing "valContaining"a[href*=/search/]
[attr~=regex]elements with an attribute named "attr", and value matching the regular expressionimg[src~=(?i)\\.(png|jpe?g)]
The above may be combined in any orderdiv.header[title]




참고 :

WebVoew에 로드된 페이지 html 소스 가져오는 방법 및 예제[ http://jabstorage.tistory.com/5 ]

Jsoup으로 파싱하기 [ http://rhkdvy1200.tistory.com/entry/Jsoup%EB%A1%9C-%ED%8C%8C%EC%8B%B1%ED%95%98%EA%B8%B0 ]


반응형