473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Java + DOM + extracting text from XHTML

I have a program, That retrieves a webpage , such as a search engine
results page from the web, Then I need to go through the document and
retrieve just the search results. The problem is I want to omit the
sponsored results. So is there a way I can start analysing the
document at a specific point (ie after the sponsored results)
Thanks

Jan 30 '07 #1
4 1672
Damo wrote:
I have a program, That retrieves a webpage , such as a search engine
results page from the web, Then I need to go through the document and
retrieve just the search results. The problem is I want to omit the
sponsored results. So is there a way I can start analysing the
document at a specific point (ie after the sponsored results)
If you can describe what that specific point is, you should be able to
write code that navigates through the document to get to that point, and
then do whatever processing you need. If you want a more detailed
answer, you'll have to ask a more specific question...
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jan 30 '07 #2
Damo wrote:
I have a program, That retrieves a webpage , such as a search engine
results page from the web, Then I need to go through the document and
retrieve just the search results. The problem is I want to omit the
sponsored results. So is there a way I can start analysing the
document at a specific point (ie after the sponsored results)
Pass the page through HTML Tidy so that it becomes well-formed XHTML.
Inspect it manually in an XML editor and find where the bits you want to
keep start. Use some kind of XPath inspector (standalone or built into
your editor) to derive a reliably unique XPath statement that will
return the bits you want. Write some XSLT code to implement this and
transform the result to the kind of output you want. Once you've done
this once, you can automate it and it will continue until some
dipsh^H^H^H^H^Hbright spark the far end decides to change the HTML of
the original page, at which point it will all break down and you'll have
to repeat the process. Organisations who don't like their pages being
sucked clean of information sometimes have random variations built into
their server to make it unpredictable where the information will appear
in the document structure, even though it appears unchanged in the
browser. Good luck :-)

Alternative: ask them if they provide an XML web service API which you
can use (probably for payment) to deliver the information in a
display-neutral form.

Warning: vacuuming pages from a web site too frequently will get your IP
address-block blacklisted.

///Peter
--
XML FAQ: http://xml.silmaril.ie
Jan 30 '07 #3
Peter Flynn wrote:
Pass the page through HTML Tidy so that it becomes well-formed XHTML.
Or use an HTML-to-XML-API parser, such as NekoHTML (part of the Xerces
family). Though Tidy has the advantage that, like a parser, it will
attempt to guess what completely bogus/broken/atrocious HTML was
intended to mean; I think NekoHTML is intended mostly for HTML that is
at least vaguely reasonable.

As Damo said, and as I hinted: If you're doing this as a personal tool,
and are willing to continue to maintain it every time the folks running
the search engine break it, you can probably make this work well enough.
If you're doing it as a business tool, whoever runs that search engine
is going to work very hard to shut you down unless you've contracted
with them -- and if you've got a contract, you can probably pay them for
an XML interface for the search that doesn't include the advertising,
avoiding the whole problem.

Remember, search results are their product. They're putting a lot of
money into the software, machines, and network resources, and they're
providing the service to noncommercial users for no fee. They really are
entitled to make a a fair profit on the commercial users and/or those
who aren't willing to look at advertising.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jan 31 '07 #4
Peter Flynn wrote:
Pass the page through HTML Tidy so that it becomes well-formed XHTML.
Or use an HTML-to-XML-API parser, such as NekoHTML (part of the Xerces
family). Though Tidy has the advantage that, like a parser, it will
attempt to guess what completely bogus/broken/atrocious HTML was
intended to mean; I think NekoHTML is intended mostly for HTML that is
at least vaguely reasonable.

As Peter said, and as I hinted: If you're doing this as a personal tool,
and are willing to continue to maintain it every time the folks running
the search engine break it, you can probably make this work well enough.
If you're doing it as a business tool, whoever runs that search engine
is going to work very hard to shut you down unless you've contracted
with them -- and if you've got a contract, you can probably pay them for
an XML interface for the search that doesn't include the advertising,
avoiding the whole problem.

Remember, search results are their product. They're putting a lot of
money into the software, machines, and network resources, and they're
providing the service to noncommercial users for no fee. They really are
entitled to make a a fair profit on the commercial users and/or those
who aren't willing to look at advertising.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jan 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
4
by: Robert Fentress | last post by:
I'm loading an xml data file and then trying to take a particular node and add it, as html, to an element on my page using inner HTML. The xml is like what is below, with the ... representing...
7
by: drum118 | last post by:
What is the current way for stating what a java script TITLE is for xhtml strict since I must be over looking it? W3 validation said there is no title. When I wrote the site 5 years ago to...
3
by: Michael Bebenita | last post by:
Hi, A Java application is encrypting a block of text using 3DES ECB mode and PKCS5 padding. I need to decrypt this text using C#. I've extracted the 192 bit key using the getEncoded() method of...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
12
by: mark2kay | last post by:
the assignment was to make list of 7 days starting with curent only that red was supposed to be in red. ive creted code only problem is its automatically makes 1st day red, which would be ok if day...
0
by: shaolinman829 | last post by:
My collegue and I are at the point of pulling our hair out. I'm currently writting a little piece of Java code to send an email confirmation page that sends both html and text. Not a problem. In my...
2
by: aglaforge | last post by:
I'm attempting to write a quick piece of Javascript code that will validate if the end user of the javascript has the necessary VML attributes set in their HTML. The problem in IE is that...
1
by: rpjd | last post by:
I am completely new to this so please bear with me here. My project involves a webpage executing php scripts via an xmlhttprequest which queries a database and returns data to the webpage. This code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.