Skip to main content

No project description provided

Project description

codecov Python Versions PyPI - Version GitHub

Articulo

Tiny library for extraction articles from html.
It can extract the content of an article, both in text and HTML, and it's title.

Usage

Basic usage

This library is designed to be as simple as possible.
To start using it just import it and instantiate with link you want to parse as a parameter.

Also the library designed to work in lazy manner.
So, until you make a request for some property, it does not send any requests.

from articulo import Articulo

# Step 1: initializing Articulo instance
article = Articulo('https://info.cern.ch/')

# Step 2: requesting article properties. All properties resolve lazily.
print(article.title) # article title as a string
print(article.text) # article content as a string
print(article.markup) # article content as an html markup string
print(article.icon) # link to article icon
print(article.description) # article meta description
print(article.preview) # link to article meta preview image
print(article.keywords) # article meta keywords list

Verbose mode

In case you want to see the whole procees just provide parameter verbose=True to the instance. It can be helpful for debugging.

from articulo import Articulo

# Initializing Articulo instance with verbose mode
article = Articulo('https://info.cern.ch/', verbose=True)

Controlling information loss coefficient

The whole idea of parsing article content is to define the part of the document that has the highest information density. To find that part there is the so-called information loss coefficient. This coefficient determines the decrease in the text density of the document during parsing.

The default value is 0.7 which stands for 70% information density decrease. In most cases, this works fine.
Nevertheless, you can change it in case you have insufficient parsing results. Just provide theshold parameter to the articulo instance, it might help.

from articulo import Articulo

# Initializing Articulo instance with information loss coefficient of 30%
article = Articulo('https://info.cern.ch/', threshold=0.3)

Providing headers

In some cases you need to provide additional headers to get an article html from url.
For that case you can provide headers with http_headers parameter when you create new instance of articulo.

from articulo import Articulo

# Initializing Articulo instance with custom user agent
headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36' }
article = Articulo('https://info.cern.ch/', http_headers=headers)

Providing custom charset

Articulo uses requests library to get html from url. This library tries to guess the encoding of the response based on the HTTP headers. Although it works fine most of the time, in some cases this might not work as expected, and you'll get a mess instead of text. For that case you can provide custom charset with def_charset parameter when you create new instance of articulo.

from articulo import Articulo

# Initializing Articulo instance with cp1251 charset
article = Articulo('https://info.cern.ch/', def_charset='cp1251')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

articulo-0.2.1.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

articulo-0.2.1-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file articulo-0.2.1.tar.gz.

File metadata

  • Download URL: articulo-0.2.1.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.9 Darwin/23.1.0

File hashes

Hashes for articulo-0.2.1.tar.gz
Algorithm Hash digest
SHA256 af7b6078b6230f1b433c63c32cf2290672b5b15df2e3c8ec97a9e7d45b590de8
MD5 162fd1d82b5ebeb2eced6150a5eb1a65
BLAKE2b-256 70263d4c080d90c9f77de4d2ed64f6c2bde3898ae845cb124f249417a7a64e6c

See more details on using hashes here.

File details

Details for the file articulo-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: articulo-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.9 Darwin/23.1.0

File hashes

Hashes for articulo-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6e3bc84b5d1cee07212f33b2529aca5b5b7f27231e3dbd7d7c7de2f229836dc
MD5 9e2512d98a2a582d84f3607a576a0932
BLAKE2b-256 e01d741b47099a140269d3e55176bb8584654955fa7f8d75dc87f3b217cccff0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page