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?
1 Answer
Yes, if you:
- Load the HTML yourself via HttpClient or something.
- Parse the HTML yourself, using an HTML parser.
- Generate the modified HTML yourself.
- Use
loadDataWithBaseURL()to load the HTML into theWebViewyourself, 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".
1 Comment
Dre
Scraping can also be considered rude and impolite ( or possibly against a websites "Terms of Use" ) for some websites.