I have had a few issues with HtmlUnit returning nulls lately and am looking for guidance. each of my results for grabbing the first row of a website have returned null. I am wondering if someone can
A) explain why they might be returning null
B) explain better ways (if there are some) to go about getting the information
Here is my current code (URL is in the source):
Right now all of my XPaths return null and .getValue() obviously doesn't work on null.
I also have questions as to what I should do about the PORT since it is an image? Is there a better alternative than downloading it and attempting to solve it by OCR?
Nota al margen
There is no significance in this site, I was just looking for a site that I could practice scraping on (the last one I ran into issues of fragment identities and couldn't get an answer to: HtmlUnit getByXpath devuelve nulo y Identidades HtmlUnit y Fragment )
preguntado el 08 de enero de 11 a las 18:01
It looks like your xpath query is incorrect. Based on the url provided in the code sample the form element should be removed from the search path.
Here is an xpath query that will be less prone to breaking when the layout of the page changes.
As far as the port number goes The author of that page must have wanted that portion of the data to not be scraped for some reason. Doing OCR might be your best option.
However, one thing you could do is look at the size of the image that is returned to guess the port number. For example I've noticed that images that display port 80 all have a content length of 406 or 411. Port 8080 are either 402 or 409. There are two different sizes to the images to blend in with the row color. If the Url ends in a 1 it will have a white back ground if it ends in 0 it will have a light grey back ground and always be a few bytes larger. There are obvious drawbacks to this approach but it may work.