在JAVA,Android中解析HTML内容和获取文本

时间:2014-04-25 17:04:42

标签: java javascript android html

我在Android应用程序中工作,该应用程序从网站获取html数据并仅解析文本(工作原理,搜索,社区等)并在屏幕上显示。

我设法从网站上获取数据,我可以在手机屏幕上看到数百行。 但现在我有点困惑,如何解析这些数据。

正如您所看到的,有不同的javascrip和html标签

<metaame=
<a href="http://www.blabla.com/how-it-works">
<div id="
<p>

并将数据包含在其中。我们在java中有什么东西可以解析所有标签并只返回文本。 (在最坏的情况下,如果我们没有这样的东西,那么我可以用&#34;&lt; p&gt;&#34;标签)获取数据。 follings是我工作的html内容中的几行。

<metaame="viewport ontent="width=device-width">
    <title>Blabla | Verified phone Community</title>
    <meta name="description" content="Blabla is the world’s largest verified mobile phone community dedicated to helping you take the right call through Caller ID and number search.">
    <meta name="apple-itunes-app" content="app-id=448142450">
    <meta name="inmobi-site-verification" content="1bed864abfbc5b2b838ca0bfd6a4331">
<div class="navbar-menu">
    <div class="navbar-menu-inner">
    <a href="http://www.blabla.com/">Search</a>
    <a href="http://www.blabla.com/how-it-works">How it works</a>
    <a href="/careers">Jobs</a>
    <a href="/blog">Blog</a>
    <a href="http://www.blabla.com/support">Support</a>
    <a class="flat-button-teal" href="http://www.blabla.com/download"><i class="icon-download icon-16"></i> Get the app</a> 
    </div>
    </div>
</div> 
    <div class="large-6 columns section-padding"> 
    <h2>Download now</h2> 
    <p>Find phone numbers, connect with people and make your phonebook beautiful.</p> 
    <p><strong>Email me a download link.</strong></p> 
    <form id="download-email-form" action="/download" method="POST" class="download-form clearfix"> 

    <button class="right" type="submit">&nbsp;</button><div class="input-holder"><input name="email" type="text" placeholder="Email"></div> 
    <div class="download-form-recaptcha"> 
    <div id="recaptcha_widget">
<ul class="footer-nav-menu">
    <li class="footer-nav-menu-title">
    This is us </li>
    <li class="footer-nav-menu-item"><button class="button-anchor" data-href="http://www.blabla.com/how-it-works">How it works</button></li>
    <li class="footer-nav-menu-item"><button class="button-anchor" data-href="http://www.blabla.com/about">About</button></li>
    <li class="footer-nav-menu-item"><button class="button-anchor" data-href="http://www.blabla.com/team">Meet the team</button></li>
    <li class="footer-nav-menu-item"><button class="button-anchor" data-href="http://www.blabla.com/story">Our story</button></li>
    <li class="footer-nav-menu-item"><button class="button-anchor" data-href="http://www.blabla.com/ambassadors">Ambassadors</button></li>
    <li class="footer-nav-menu-item"><button class="button-anchor" data-href="http://www.blabla.com/jobs">Jobs</button></li>
    <li class="footer-nav-menu-item"><button class="button-anchor" data-href="http://www.blabla.com/contact">Contact</button></li>
    </ul>

1 个答案:

答案 0 :(得分:0)

您可以尝试查看这样的Java HTML解析器:http://jsoup.org/