473,782 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1693
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^H bright 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
3109
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 Transformer convert that via XSLT to valid XSL-FO. So I define a SAXReader which fires the SAX Events for the Java Object. This works fine and the Transformation to PDF is ok. However, I have one object which contains an XHTML String and the tags
4
1287
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 eliminated detail: <?xml version="1.0" encoding="iso-8859-1"?> <table> <descriptions> <fielddesc id="1"> ...
7
2619
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 strict xhtml which was validated at w3 site it was like this as well for Bobby: <a id="back"><!-- Today Date --></a> <script type="text/javascript" src="pages/js/today.js" title="Today Date"> </script>
3
7785
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 the SecretKey Java class. However when I use this key in .NET i cannot decrypt the cipher text. I am pretty sure that all my settings are correct, as far as setting the ECB mode, PKCS5 padding and converting the cipher text to byte
18
7739
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); System.out.println(xp.evaluate(new InputSource(new FileInputStream("a.xml"))));
12
1556
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 is sunday but 6 days out of week assignment will be wrong, heres code. "<html><title>Marks JS</title> <body> <font size = "4"> <script language = "JavaScript">
0
8757
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 html, I'm using an image with which I reference through a cid i1. My problem is, in the email I send, I can only get the images to show up if I do: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
2
2567
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 "xmlns:v" does not appear in their attributes property or the getAttribute('xmlns:v') calls. The real kicker is that the 'xmlns' attribute does return something. The HTML Snippet would look like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
1
1948
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 below is working to a degree in IE7. As I have not yet parsed http.responseText, I am getting all the code in parts.php in the alert. My php script query creates two php arrays, one a single array and a two-dimensional array such as array. My...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.