如何在UIWebview上获取类的超链接?

时间:2015-03-13 21:07:26

标签: class hyperlink uiwebview

我可以通过以下代码获取课程文本:

[webview stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('normal fs16 bold c-red2')[0].innerHTML;"];

但我还需要获得此课程的链接。

1 个答案:

答案 0 :(得分:0)

我刚刚解决了网站的所有链接并使用字符串:

[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"function getHyperlinks() { "
     "var links = document.getElementsByTagName('a');"
     "var allLinks = '';"
     "for (var i = 0; i<links.length; i++) {"
     "var link = links[i].href + '~' + links[i].text + '~' + links[i].title + ';';"
     "allLinks += link;"
     "} return allLinks;"
     "}\";"
     "document.getElementsByTagName('head')[0].appendChild(script);"];


    NSString *html = [webView stringByEvaluatingJavaScriptFromString:
                      @"getHyperlinks();"];