This is the main text.
{ "cells": [ { "cell_type": "markdown", "id": "sec-title", "metadata": {}, "source": [ "# Trafilatura: Overview\n", "\n", "A hands-on tour of the main features. For full documentation see [trafilatura.readthedocs.io](https://trafilatura.readthedocs.io/)." ] }, { "cell_type": "markdown", "id": "sec-install", "metadata": {}, "source": [ "## 1. Installation\n", "\n", "```bash\n", "pip install trafilatura\n", "```\n", "\n", "To update: `pip install -U trafilatura`. For more info see [Installation](https://trafilatura.readthedocs.io/en/latest/installation.html)." ] }, { "cell_type": "markdown", "id": "sec-quickstart", "metadata": {}, "source": [ "## 2. Quick start\n", "\n", "Download a web page and extract its main text:" ] }, { "cell_type": "code", "execution_count": null, "id": "quickstart-code", "metadata": {}, "outputs": [], "source": [ "from trafilatura import extract, fetch_url\n", "\n", "url = \"https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/\"\n", "downloaded = fetch_url(url)\n", "\n", "text = extract(downloaded)\n", "print(text[:500])" ] }, { "cell_type": "markdown", "id": "sec-inputs", "metadata": {}, "source": [ "## 3. Input formats\n", "\n", "`extract()` accepts HTML as a string or as a pre-parsed LXML tree." ] }, { "cell_type": "code", "execution_count": null, "id": "input-string", "metadata": {}, "outputs": [], "source": [ "# from a local file\n", "# with open('myfile.html', encoding='utf-8') as f:\n", "# text = extract(f.read())\n", "\n", "# from an HTML string\n", "my_html = \"
This is the main text.