Android parsing HTML?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
51 views
Good afternoon, I sorted this example habrahabr.ru/blogs/android/91815/piece of code where the parsed user profile for finding avatars. There are all realized through working with a string one substring().

The question arose: is it Possible to run through the DOM of the received document, as, for example, with jQuery based on the classes and IDs of elements?

Or, maybe, tell me more humane method of obtaining information from the page.

Thank you!
by | 51 views

6 Answers

0 like 0 dislike
Tell me, what is the task? After all, you can use the regular season.
\r
For example, I was pulling values from the html page:
\r
\r
 public String GetTemper(String urlsite) // function of loading temperature { Matchtemper String = ""; try { // loading page URL URL = new URL(urlsite); URLConnection conn = url.openConnection(); An InputStreamReader rd = new an InputStreamReader(conn.getInputStream()); Allpage StringBuilder = new StringBuilder(); int n = 0; char[] buffer = new char[40000]; while (n >= 0) { n = rd.read(buffer, 0, buffer.length); if (n > 0) { allpage.append(buffer, 0, n); } } // work with regexps final Pattern pattern = Pattern.compile ("[^-+0]+([-+0-9]+)[^<]+[^(a-za-Aeea-zA-Z0-9)]+([a-za-Aeea-zA-Z ]+)"); Matcher matcher = pattern.matcher(allpage.toString()); if (matcher.find()) { matchtemper = matcher.group(1); } return matchtemper; } catch (Exception e) { } return matchtemper; }; 
by
0 like 0 dislike
The theme is interesting, I googled a bit and realized that parsing is to do with Xml parsing, although the approach is controversial because html is not always valid Xml, with regard to libraries for operation with Dom, then today, as I understand it, there is nothing like this.
\r
Links that may be helpful:
\rAndroid HTML Dom (link in reply)
\rAndroid parsing HTML entities using DOM parser for RSS feed
by
0 like 0 dislike
For your purposes you can use, for example, htmlcleaner. A simple library for Dom-parsing.
There is still an Html Parser, it is quite bulky, but it supports CSS selectors.
In terms of speed, of course, it is best to use SAX xml parser.
by
0 like 0 dislike
In my app, I for this purpose use a bunch of TagSoup (generator valid XHTML from virtually any HTML) and SAX Parser. Works well.
by
0 like 0 dislike
Forgot — with version 2.2 (I think) Android has finally added support for XPath, the mind is just the tool for this purpose. But again, we need TagSoup or some other tool to get valid xhtml.
by
0 like 0 dislike
The most humane Jsoup . Simple and fast. Only now I have Android 4.4 on why the brakes impossible (while on 2.2 the same code flies). In General check on virtual machines.
by

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
3 answers
asked May 20, 2019 by mezencevsem
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
27,872 users