Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Getting data from html table in java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to getting some data in html page,
here is the sample of the html page

---------htmlPage---------



here is the java code

-------java code----------





but tihs code can not get data from this html page correctly
 
Sheriff
Posts: 15810
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Erçin Kirpik wrote:
but tihs code can not get data from this html page correctly


Hello, Erçin. Welcome to the Ranch!

Honestly, my first reaction to seeing your listing and what you're trying to do was "Why the heck would you want to do that?!" HTML is for display, not for storing and retrieving data. That said, parsing the HTML and walking through the DOM tree is possible. Your code will most likely end up being brittle though because it will be strongly tied to the exact structure of this HTML.

In particular, this line of code is pretty bad:

You're looking for a table with a specific background color. It may be all you can do to identify a specific table but it's still, as we sometimes say, "Icky" (distasteful). At any rate, what you're trying to do amounts to reverse-engineering the HTML. If this is really what you need to do, then I suggest you understand what the HtmlTable class really does. As far as I can tell, it doesn't do what you think it does.

Is there no other way that you can get the data, perhaps from a different source? How was this HTML generated in the first place?
 
Erçin Kirpik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for answer,

The html page another web page and i get the data from the web page.
Also, i must get data from this page there is no other way to get the data.
 
Junilu Lacar
Sheriff
Posts: 15810
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Erçin Kirpik wrote:but tihs code can not get data from this html page correctly


Well then, please TellTheDetails (←click) because ItDoesntWorkIsUseless (←click)
 
Erçin Kirpik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you again for answer,

for instance
this html page have some data in the table
i can get third data column and fifth data column but other data column i can not get, also, in the html page same structure but there are one or two data columns this time i can not get any data
 
Junilu Lacar
Sheriff
Posts: 15810
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, this code is messy to say the least. If it were me, I would first clean this up.

Problems:
1. This code is doing multiple things: extracting data from the Html, transforming the text read from the Html table (with call to replaceAll()), building up a SQL statement, and executing the SQL statement.
2. The details of how you're doing things is seriously obscuring the intent of the program - it's confusing to read. Your formatting of the code doesn't help either.

Suggested refactorings:
1. Break down the processing of the HTML into smaller steps. First extract the data to an appropriate data structure. Then tweak the data with replaceAll(). Then build up the SQL statement from the data. Then execute the SQL statement.
2. Test your results for each step of the process. Don't proceed to the next step until you're sure the current step REALLY works as you intend it to work.

Remember: Premature optimization is the root of all evil.
 
I found some pretty shells, some sea glass and this lovely tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic