I'm trying to parse an HTML page in my app but I get a mobile version of that page without block I need. Is there any way to get the desktop version of the page?
Asked
Active
Viewed 101 times
2 Answers
2
How are you trying to download the html page? i am guessing with some sort of webview.
if you download it like this, it should have the full content of the desktop version:
URL url = new URL("https://stackoverflow.com/questions/1381617");
URLConnection con = url.openConnection();
Reader r = new InputStreamReader(con.getInputStream(), Charset.forName("UTF-8"));
StringBuilder b = new StringBuilder();
while (true) {
int ch = r.read();
if (ch < 0)
break;
b.append((char) ch);
}
String s = b.toString();
from Simplest way to correctly load html from web page into a string in Java
-
Thanks, but I wanted to get the desktop version of a page and needed to imitate a desktop device. – Alexey Sobolevsky Nov 25 '14 at 15:20
1
You should set Headers for your request. I guess, you should set User-Agent header to get full version.
For example, if you use HttpGet, than:
DefaultHttpClient httpClient = new DefaultHttpClient();
final HttpParams httpParameters = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 8 * 1000);
HttpConnectionParams.setSoTimeout(httpParameters, 8 * 1000);
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0");

Suvitruf - Andrei Apanasik
- 5,582
- 9
- 49
- 88