Home  >  Article  >  Backend Development  >  Relative Python RSS service description

Relative Python RSS service description

Y2J
Y2JOriginal
2017-05-06 09:30:161805browse

The most successful XML service so far is Python RSS. Although its origins are very confusing, the Python language is indeed a great RSS processing tool. This article introduces some modules that can be used for RSS processing.

RSS is an abbreviation that can be represented by various extensions: "RDF Site Summary (RDF Site Summary)", "Really Simple Syndication", "Rich Site" Summary (Rich Site Summary)". Perhaps other extensions can be used to express it. Behind such a confusing name, you'll find a surprising number of stories related to such a mundane area of ​​technology.

RSS is a simple XML format used for distributing summaries of content on a Web site. It can be used to share a wide variety of information, including (but not limited to) newsletters, Web site updates, event calendars, software updates, featured content collections, and Web-based content. Items for auction.

Python RSS was created by Netscape in 1999 and allowed content from many information sources to be aggregated into the Netcenter portal (this portal now no longer exists). Web enthusiasts in the UserLand community became early supporters of RSS, and RSS quickly became a very popular format. This popularity makes it difficult for people to improve RSS so that it can be used in more places. This limitation led to divergence in the development of RSS. One group chose an RDF-based approach, aiming to take advantage of the large number of RDF tools and modules, while the other group chose a more compact approach.

The former is called RSS 1.0, while the latter is called RSS 0.91. Just last month the competition between the two intensified with the emergence of a new version of the non-RDF variant of RSS, which its creators are calling "RSS 2.0".

RSS 0.91 and 1.0 are very popular and used by numerous portals and web logs. In fact, the blogging community is a major user of RSS, which is why some of the existing networks for XML exchange are impressive.

These networks have grown organically and have truly become the most successful XML serving networks in existence. RSS becomes an XML service because it is used to exchange XML information over the Internet protocol (the vast majority of RSS exchanges are simple HTTP GET of Python RSS documents).

In this article, we have introduced just a few of the many Python tools that can work with RSS. We won't provide a technical introduction to RSS, as you can get that in many other articles.

(See Resources). We recommend that you first become briefly familiar with RSS knowledge and understand XML. You don't need to understand RDF. [Because RSS uses XML description instead of

WSDL

, we treat RSS as an "XML service" rather than a "Web service". - Editor's Note]

RSS.py written by Mark Nottingham is a Python library for RSS processing. It's very complete and well written. It requires Python 2.2 and PyXML 0.7.1. Its

Installation is very simple; you just download the Python file from Mark's homepage and copy it somewhere in your PYTHONPATH.

Most users of RSS.py themselves only need to care about the two classes it provides: CollectionChannel and TrackingChannel. The latter seems to be the more useful of the two classes. TrackingChannel is a data structure that contains all RSS data indexed by the keyword of each item. CollectionChannel is a similar data structure, but its structure is more like the RSS document itself.

Its top-level channel information points to the item details using a hash value represented by the URL. You will most likely use the utility namespace declaration in the RSS.ns structure. Listing 1 is a simple script that will download and parse the Python RSS feed for Python news and print all the information from each item in a simple list.

We start by creating a TrackingChannel instance and filling it with data parsed from the RSS feed at http://www.python.org/channews.rdf. RSS.py uses tuples as

propertynames for RSS data.

Instructions on the wide application of Python system programs

Illustrated introduction to the functions of Python applications

Introduction to the application fields of Python

Using Python scripting language for programming Edit

Analysis of Python development program principles

For those who are not used to XML processing technology, this method may seem unusual, but it is indeed a very effective way to accurately understand the content of the original RSS file. Therefore, an RSS 0.91 title element is considered different from an RSS 1.0 element of the same name.

The application has enough data to ignore this difference, if you wish, by ignoring the namespace part of each tuple; but the basic API is the same as The syntax of the original RSS file is combined, so this information is not lost.

In the code, we use this attribute data to aggregate all items in the news feed for display. Note that we are careful not to assume what properties any particular item might have. We use the safe form shown in the following code to retrieve the properties.

【Related Recommendations】

1. RSS College Introductory Tutorial

The above is the detailed content of Relative Python RSS service description. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Let you know what RSS isNext article:Let you know what RSS is