I am new in Kotlin Programming and I want to get Google html content
But i don't know how can I do this
Asked
Active
Viewed 5,958 times
-2

Salman Daryanavard
- 21
- 1
- 3
-
Welcome to StackOverflow. Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. See the [How to Ask](https://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – Bob Aug 19 '17 at 14:47
1 Answers
6
You can use HttpUrlConnection
(Java example) but I recommend using higher level libraries like Jsoup. You can then use CSS selectors to get specific elements from the document (so you may not actually need the HTML code in your app).
You can fetch Google's index page this way:
val doc = Jsoup.connect("http://google.com/").get()
val html = doc.outerHtml()
If you need the raw HTML which is sent by Google, you can use this code:
val conn = Jsoup.connect("http://google.com/").method(Method.GET)
val resp = conn.execute()
val html = resp.body()

juzraai
- 5,693
- 8
- 33
- 47