1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Join our Telegram chat: https://t.me/a_parser_en
    Dismiss Notice

Parsing RSS

Discussion in 'Share Experience' started by Support, Sep 22, 2015.

  1. Support

    Support Administrator
    Staff Member A-Parser Enterprise

    Joined:
    Mar 16, 2012
    Messages:
    4,435
    Likes Received:
    2,123
    The purpose of this article - to show the general direction in parsing RSS. As an example, we will use RSS of our forum: http://en.a-parser.com/forum/english-news/index.rss. This preset may be used for other sites, but due to different standards, may need to make some modifications.

    The process of parsing is quite simple and consists mainly of information search using regular expressions and its output to the result file.[​IMG]
    [​IMG]
    • Use Net::HTTP Net::HTTP
    • The proxy may not be used
    • First parse all <item>...</item>
    • Then from the resulting array parse the necessary information. In this example: title, date, URL and content.
    • Purified from the superfluous elements (in the example it is HTML tags and entities, as well as other residual lines).
    • Outputs a result using the capabilities of Template Toolkit, in the desired format.
    When parsing such a way that, if at some moment is not the desired parameter in the body of RSS feed, it simply will empty the integrity and consistency of information can not be broken (on the specification of RSS, all the parameters are optional, so may skip). The result is a file with the same contents:
    eyJwcmVzZXQiOiJSU1MiLCJ2YWx1ZSI6eyJwcmVzZXQiOiJSU1MiLCJwYXJzZXJz IjpbWyJOZXQ6OkhUVFAiLCJkZWZhdWx0Iix7InR5cGUiOiJjdXN0b21SZXN1bHQi LCJyZXN1bHQiOiJkYXRhIiwicmVnZXgiOiI8aXRlbT4oLis/KTxcXC9pdGVtPiIs InJlZ2V4VHlwZSI6InNnIiwicmVzdWx0VHlwZSI6ImFycmF5IiwiYXJyYXlOYW1l IjoiaXRlbXMiLCJyZXN1bHRzIjpbIml0ZW0iXX0seyJ0eXBlIjoib3ZlcnJpZGUi LCJpZCI6InVzZXByb3h5IiwidmFsdWUiOmZhbHNlfSx7InR5cGUiOiJjdXN0b21S ZXN1bHQiLCJyZXN1bHQiOlsiaXRlbXMiLCJpdGVtIl0sInJlZ2V4IjoiPHRpdGxl PiguKz8pPFxcL3RpdGxlPiIsInJl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