如何解析Android中的网页 [英] How to parse web page in android
问题描述
我有一个网页URL http://m.cricbuzz.com/cricket-match /活比分该页面的源代码是< DIV CLASS =列表组>< H4类=列表组项UI头> ENG与朴,悉尼< / H4>< / DIV>
我要ENG与朴,悉尼,请HEPL我
JSoup就是这样的一个开放源码库,提供了一个API,用于
提取和操作数据。基本上,它是用一种HTML解析器
对于各种HTML元素的工作,属性等,还可以
发现和提取数据,使用DOM遍历或CSS选择器。
块引用>字符串的html =< P>一种< A HREF =HTTP://example.com/'>< B>例如< / B>< / A>链接< / p>中;
文档的DOC = Jsoup.parse(HTML);
元件连结= doc.select(A)的第一();。字符串文本= doc.body()文本(); //的一个例子链接
字符串linkHref = link.attr(HREF); //http://example.com/
字符串LINKTEXT = link.text(); //榜样串linkOuterH = link.outerHtml();
//&下; A HREF =http://example.com>&所述b取代;例如与下/ B个;&下; / A>中
串linkInnerH = link.html(); //< B>例如< / B>中i have a web url http://m.cricbuzz.com/cricket-match/live-scores which page source is
<div class="list-group"><h4 class="list-group-item ui-header">ENG vs PAK, Sydney</h4></div>
I want ENG vs PAK, Sydney,please hepl me
解决方案JSoup is one such open source library that provides an API for extracting and manipulating data. Basically, it is an HTML parser used for working with various HTML elements, attributes etc. It can also find and extract data, using DOM traversal or CSS selectors.
String html = "<p>An <a href='http://example.com/'><b>example</b></a> link.</p>"; Document doc = Jsoup.parse(html); Element link = doc.select("a").first(); String text = doc.body().text(); // "An example link" String linkHref = link.attr("href"); // "http://example.com/" String linkText = link.text(); // "example"" String linkOuterH = link.outerHtml(); // "<a href="http://example.com"><b>example</b></a>" String linkInnerH = link.html(); // "<b>example</b>"
Visit this it will help you with your problem, with that have a look on cookbook
这篇关于如何解析Android中的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!