Melih Akalan
Melih Akalan

Reputation: 61

Android HTTP Request - Get text only

is there any way to request only text on a web page?

For example, there are too many images in the page, so I don't want to get images in < img src > tags.

Upvotes: 0

Views: 479

Answers (3)

soundsofpolaris
soundsofpolaris

Reputation: 596

If you request a page via an HTTPClient it will return the HTML markup in the HTMLResponse. From there you can regex/parse out the text. At the point when the markup is returned, no images have loaded.

If you are talking about requesting the page in a WebView, then no, that is not possible.

Upvotes: 1

Rohan Singh
Rohan Singh

Reputation: 21535

You can make an HTTP request that retrieves just HTML. This answer provides an example of how to make an HTTP request.

You'll get back all the HTML including <img> tags — that's unavoidable. However, you don't have to fetch the actual contents of the image tags. Instead, you can use an HTML parser like android.text.Html, jsoup, or TagSoup to read just the text contents.

android.text.Html, in particular, might be useful. From the doc for Html.fromHtml:

Any <img> tags in the HTML will display as a generic replacement image which your program can then go through and replace with real images.

If you want to display this HTML to the user, you can then do so as described here.

Upvotes: 0

Cata
Cata

Reputation: 11211

No, I don't think there is a way to do that unless you use a web service and then you can call web service methods that may serve you only what you need...

Basically when you make a request to a web page, the server's response would be to give you the entire page content so if you don't have control over the server side, you won't have the possibility to request only specific data.

Upvotes: 0

Related Questions