Get Specific elements from HTML in UIWebView

馋奶兔 提交于 2019-12-10 22:14:05

问题


how can i get specific elements from html page if i have this nsstring with this value

<body style="background-color: 3399CC;font-size: 200.5%;font-family:monospace;font-style:oblique;">


<div id="1" align="center" style="padding-top: 10%;" >
 <h1 style="color: #FFFFFF">fawazapp</h1>
 <p style="color: #C0C0C0;"> bbb</p>
 <p style="color: #FFFFFF;">aaaaaaaaa</p>

 </div>

<div id="2" align="center" style="padding-top: 10%;" >
 <h1 style="color: #FFFFFF">fawazapp</h1>
 <p style="color: #C0C0C0;"> bbb</p>
 <p style="color: #FFFFFF;">aaaaaaaaa</p>

 </div>

I want to clear everything except div with id number 2 to be like this

 </div>

<div id="2" align="center" style="padding-top: 10%;" >
 <h1 style="color: #FFFFFF">fawazapp</h1>
 <p style="color: #C0C0C0;"> bbb</p>
 <p style="color: #FFFFFF;">aaaaaaaaa</p>

 </div>

回答1:


UIWebView has a method stringByEvaluatingJavaScriptFromString: so if you have (or create) some javascript to navigate / manipulate / interrogate the page contents you can run it to obtain the result.



来源:https://stackoverflow.com/questions/17522181/get-specific-elements-from-html-in-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!