<p>I'm planning to write a simple J2SE application to aggregate information from multiple web sources.</p>

<p>The most difficult part, I think, is extraction of meaningful information from web pages, if it isn't available as RSS or Atom feeds. For example, I might want to extract a list of questions from stackoverflow, but I absolutely don't need that huge tag cloud or navbar.</p>

<p>What technique/library would you advice?</p>

<p><strong>Updates/Remarks</strong></p>

<ul>
<li>Speed doesn't matter — as long as it can parse about 5MB of HTML in less than 10 minutes.</li>
<li>It sould be really simple.</li>
</ul>

[{'answer_id': 71508, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>In short, you may either parse the whole page and pick things you need(for speed I recommend looking at SAXParser) or running the HTML through a regexp that trims of all of the HTML... you can also convert it all into DOM, but that's going to be expensive especially if you're shooting for having a decent throughput.</p>\n"}, {'answer_id': 71510, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>You seem to want to screen scrape. You would probably want to write a framework which via an adapter / plugin per source site (as each site's format will differ), you could parse the html source and extract the text. you would prob use java's io API to connect to the URL and stream the data via InputStreams.</p>\n"}, {'answer_id': 71516, 'author': 'James Law', 'author_id': 11855, 'author_profile': 'https://Stackoverflow.com/users/11855', 'pm_score': 2, 'selected': False, 'text': '<p>You could look at how httpunit does it. They use couple of decent html parsers, one is nekohtml.\nAs far as getting data you can use whats built into the jdk (httpurlconnection), or use apache\'s </p>\n\n<p><a href="http://hc.apache.org/httpclient-3.x/" rel="nofollow noreferrer">http://hc.apache.org/httpclient-3.x/</a></p>\n'}, {'answer_id': 71530, 'author': 'jatanp', 'author_id': 959, 'author_profile': 'https://Stackoverflow.com/users/959', 'pm_score': 2, 'selected': False, 'text': '<p>You may use HTMLParser (<a href="http://htmlparser.sourceforge.net/)in" rel="nofollow noreferrer">http://htmlparser.sourceforge.net/)in</a> combination with URL#getInputStream() to parse the content of HTML pages hosted on Internet.</p>\n'}, {'answer_id': 71577, 'author': 'Vhaerun', 'author_id': 11234, 'author_profile': 'https://Stackoverflow.com/users/11234', 'pm_score': 0, 'selected': False, 'text': "<p>If you want to do it the old fashioned way , you need to connect with a socket to the webserver's port , and then send the following data :</p>\n\n<pre><code>GET /file.html HTTP/1.0\nHost: site.com\n&lt;ENTER&gt;\n&lt;ENTER&gt;\n</code></pre>\n\n<p>then use the <code>Socket#getInputStream</code> , and then read the data using a BufferedReader , and parse the data using whatever you like.</p>\n"}, {'answer_id': 71690, 'author': 'Joe Liversedge', 'author_id': 4552, 'author_profile': 'https://Stackoverflow.com/users/4552', 'pm_score': 2, 'selected': False, 'text': '<p>If you want to take advantage of any structural or semantic markup, you might want to explore converting the HTML to XML and using XQuery to extract the information in a standard form. Take a look at <a href="http://www.ibm.com/developerworks/xml/library/j-jtp03225.html" rel="nofollow noreferrer">this IBM developerWorks article</a> for some typical code, excerpted below (they\'re outputting HTML, which is, of course, not required):</p>\n\n<pre><code>&lt;table&gt;\n{\n  for $d in //td[contains(a/small/text(), "New York, NY")]\n  for $row in $d/parent::tr/parent::table/tr\n  where contains($d/a/small/text()[1], "New York")\n  return &lt;tr&gt;&lt;td&gt;{data($row/td[1])}&lt;/td&gt; \n           &lt;td&gt;{data($row/td[2])}&lt;/td&gt;              \n           &lt;td&gt;{$row/td[3]//img}&lt;/td&gt; &lt;/tr&gt;\n}\n&lt;/table&gt;\n</code></pre>\n'}, {'answer_id': 71735, 'author': 'Alexandre Victoor', 'author_id': 11897, 'author_profile': 'https://Stackoverflow.com/users/11897', 'pm_score': 0, 'selected': False, 'text': '<p>You can use <a href="http://sourceforge.net/projects/nekohtml" rel="nofollow noreferrer">nekohtml</a> to parse your html document. You will get a DOM document. You may use XPATH to retrieve data you need.</p>\n'}, {'answer_id': 71975, 'author': 'Maxim', 'author_id': 11587, 'author_profile': 'https://Stackoverflow.com/users/11587', 'pm_score': 0, 'selected': False, 'text': '<p>If your "web sources" are regular websites using HTML (as opposed to structured XML format like RSS) I would suggest to take a look at <a href="http://htmlunit.sourceforge.net/" rel="nofollow noreferrer">HTMLUnit</a>. </p>\n\n<p>This library, while targeted for testing, is a really general purpose "Java browser". It is built on a Apache httpclient, Nekohtml parser and Rhino for Javascript support. It provides a really nice API to the web page and allows to traverse website easily.</p>\n'}, {'answer_id': 72027, 'author': 'Eric  DeLabar', 'author_id': 7556, 'author_profile': 'https://Stackoverflow.com/users/7556', 'pm_score': 0, 'selected': False, 'text': '<p>Have you considered taking advantage of RSS/Atom feeds?  Why scrape the content when it\'s usually available for you in a consumable format?  There are libraries available for consuming RSS in just about any language you can think of, and it\'ll be a lot less dependent on the markup of the page than attempting to scrape the content.  </p>\n\n<p>If you absolutely MUST scrape content, look for <a href="http://microformats.org" rel="nofollow noreferrer">microformats</a> in the markup, most blogs (especially WordPress based blogs) have this by default.  There are also libraries and parsers available for locating and extracting microformats from webpages.</p>\n\n<p>Finally, aggregation services/applications such as <a href="http://pipes.yahoo.com/pipes/" rel="nofollow noreferrer">Yahoo Pipes</a> may be able to do this work for you without reinventing the wheel.</p>\n'}, {'answer_id': 4841760, 'author': 'VNVN', 'author_id': 495337, 'author_profile': 'https://Stackoverflow.com/users/495337', 'pm_score': 0, 'selected': False, 'text': '<p>Check this out <a href="http://www.alchemyapi.com/api/demo.html" rel="nofollow">http://www.alchemyapi.com/api/demo.html</a></p>\n\n<p>They return pretty good results and have an SDK for most platforms. Not only text extraction but they do keywords analysis etc.</p>\n'}]
['https://Stackoverflow.com/questions/71491', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1764/']