Parsing web pages

后端 未结 3 1383
伪装坚强ぢ
伪装坚强ぢ 2021-01-07 07:14

I have a question about parsing HTML pages, specificaly forums, i want to parse a forum or thread containing certain post criterias, i havent defined the algorithm yet, si

相关标签:
3条回答
  • 2021-01-07 07:56

    You might want to look into some sort of html parsing library, rather than using regular expressions to do this. There are some really good html parsers for ruby and python, but a quick google shows there to be a number of parsers for java as well. The benefit of these libraries is that you don't have to handle every edge case with regular expressions/they handle malformed html (both of which can be impossible with regexes, depending on what you want to do) and they also give you a much way of dealing with the data (for example, beautiful soup lets you grab all elements which belong to a specific class or to use some other css selector to limit which page elements you want to deal with).

    Personally, I would, at least for the beginning, start in ruby or python, as the libraries are known and there is a lot of info about using them for this purpose. Also, I find it easier to quickly prototype these types of things in ruby or python than in the jvm. You could even later bring that code onto the jvm with jruby or jython, if it becomes necessary.

    0 讨论(0)
  • 2021-01-07 08:04

    1 / yes

    2 / Use some compact language like python or ruby for prototyping.

    • For python there is a neat library for HTML/XML parsing called beautifulsoup

    • For ruby, you could try: nokogiri or hpricot

    3 / A Java tool to consider: htmlparser

    4 / If you are interested only in some particular text or some special classes, a regular expression might be sufficient. But as soon as you want to dig deeper into the structure of the content, you'll need some kind of model to hold your data, and hence a parser, which, in the best case, can cope with the occuring incosistencies of real world html.

    0 讨论(0)
  • 2021-01-07 08:09
    1. yes
    2. regular expressions, any flavor.
    3. probably the ones w/regex
    4. there are tools out there that will do this for you.
    0 讨论(0)
提交回复
热议问题