Roger
Roger

Reputation: 4259

Parse site in WebView?

I'm loading a 3rd party website into my app using WebView. But there is a lot of items I don't want to see. Is there a way to parse just the pieces that I want?

Upvotes: 1

Views: 242

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006799

Yes, if you:

  1. Load the HTML yourself via HttpClient or something.
  2. Parse the HTML yourself, using an HTML parser.
  3. Generate the modified HTML yourself.
  4. Use loadDataWithBaseURL() to load the HTML into the WebView yourself, using your original URL as the "base URL" so relative links and images work.

Or, since this is hopefully your Web server, you simply create a separate Web page that has what you want.

Or, if it is not your Web server, use the site's Web service API instead of scraping Web content, which is intrinsically unreliable, since minor changes in the page layout may break your parsing logic.

Or, just display the "lot of items".

Upvotes: 2

Related Questions