Skip to main content

ExtractNet

PyPI version codecov

Based on the popular content extraction package Dragnet, ExtractNet extend the machine learning approach to extract other attributes such as date, author and keywords from news article.

demo code

Example code:

Simply use the following command to install the latest released version:

pip install extractnet

Start extract content and other meta data passing the result html to function

import requests
from extractnet import Extractor

raw_html = requests.get('https://currentsapi.services/en/blog/2019/03/27/python-microframework-benchmark/.html').text
results = Extractor().extract(raw_html)

Why don't just use existing rule-base extraction method:

We discover some webpage doesn't provide the real author name but simply populate the author tag with a default value.

For example ltn.com.tw, udn.com always populate the same author value for each news article while the real author can only be found within the content.

Our machine learnig first approach extract correct fields just like human reading a website

ExtractNet uses machine learning approach to extract these relevant data through visible section of the webpage just like a human.

ExtractNet pipeline

What ExtractNet is and isn't

  • ExtractNet is a platform to extract any interesting attributes from any webpage, not just limited to content based article.

  • The core of ExtractNet aims to convert unstructured webpage to structured data without relying hand crafted rules

  • ExtractNet do not support boilerplate content extraction

  • ExtractNet allows user to add custom pipelines that returns additional data through a list of callbacks function


Performance

Results of the body extraction evaluation:

We use the same body extraction benchmark from article-extraction-benchmark

Model Precision Recall F1 Accuracy Open Source
AutoExtract 0.984 ± 0.003 0.956 ± 0.010 0.970 ± 0.005 0.470 ± 0.037 ✗
Diffbot 0.958 ± 0.009 0.944 ± 0.013 0.951 ± 0.010 0.348 ± 0.035 ✗
ExtractNet 0.922 ± 0.011 0.933 ± 0.013 0.927 ± 0.010 0.160 ± 0.027 ✔
boilerpipe 0.850 ± 0.016 0.870 ± 0.020 0.860 ± 0.016 0.006 ± 0.006 ✔
dragnet 0.925 ± 0.012 0.889 ± 0.018 0.907 ± 0.014 0.221 ± 0.030 ✔
html-text 0.500 ± 0.017 0.994 ± 0.001 0.665 ± 0.015 0.000 ± 0.000 ✔
newspaper 0.917 ± 0.013 0.906 ± 0.017 0.912 ± 0.014 0.260 ± 0.032 ✔
readability 0.913 ± 0.014 0.931 ± 0.015 0.922 ± 0.013 0.315 ± 0.034 ✔
trafilatura 0.930 ± 0.010 0.967 ± 0.009 0.948 ± 0.008 0.243 ± 0.031 ✔

Results of author name extraction:
Model F1
ExtractNet : fasttext embeddings + CRF 0.904 ± 0.10

List of changes from Dragnet

  • Underlying classifier is replaced by Catboost instead of Decision Tree for all attributes extraction for consistency and performance boost.

  • Updated CSS features, added text+css latent feature

  • Includes a CRF model that extract names from author block text.

  • Trained on 22000+ updated webpages collected in the late 2020, 20 times of dragnet data.

GETTING STARTED

Installing and extraction

pip install extractnet
from extractnet import Extractor

raw_html = requests.get('https://apnews.com/article/6e58b5742b36e3de53298cf73fbfdf48').text
results = Extractor().extract(raw_html)
for key, value in results.items():
    print(key)
    print(value)
    print('------------')

Callbacks

ExtractNet also support the ability to add callbacks functions to inject additional features during extraction process

A quick glance of usage : each callbacks will be able to access the raw html string provided during the extraction process. This allows user to extract addtional information such as language detection to the final results

def meta_pre1(raw_html):
    return {'first_value': 0}

def meta_pre2(raw_html):
    return {'first_value': 1, 'second_value': 2}

def find_stock_ticker(raw_html, results):
    matched_ticker = []
    for ticket in re.findall(r'[$][A-Za-z][\S]*', str(results['content'])):
      matched_ticker.append(ticket)
    return {'matched_ticker': matched_ticker}

extract = Extractor(author_prob_threshold=0.1, 
      meta_postprocess=[meta_pre1, meta_pre2], 
      postprocess=[find_stock_ticker])

The extracted results will contain like, first_value and second_value. Do note callbacks are executed by the given order ( which means meta_pre1 will be executed first followed by meta_pre2 ), any results passed from the previous stage will not be overwritten by later stage

raw_html = requests.get('https://apnews.com/article/6e58b5742b36e3de53298cf73fbfdf48').text
results = extract(raw_html)

In this example the value for first_value will remain 0 even though meta_pre2 also returns first_value=1 because meta_pre2 callbacks already assign first_value as 0.

Contributing

We love contributions! Open an issue, or fork/create a pull request.

More details about the code structure

Coming soon

Reference

Content extraction using diverse feature sets

[1] Peters, Matthew E. and D. Lecocq, Content extraction using diverse feature sets

@inproceedings{Peters2013ContentEU,
  title={Content extraction using diverse feature sets},
  author={Matthew E. Peters and D. Lecocq},
  booktitle={WWW '13 Companion},
  year={2013}
}

Bag of Tricks for Efficient Text Classification

[2] A. Joulin, E. Grave, P. Bojanowski, T. Mikolov, Bag of Tricks for Efficient Text Classification

@article{joulin2016bag,
  title={Bag of Tricks for Efficient Text Classification},
  author={Joulin, Armand and Grave, Edouard and Bojanowski, Piotr and Mikolov, Tomas},
  journal={arXiv preprint arXiv:1607.01759},
  year={2016}
}

Metadata

Release files for extractnet 2.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for extractnet 2.0.4
File Size Uploaded
extractnet-2.0.4.tar.gz 1.8 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for extractnet 2.0.4
File
extractnet-2.0.4-cp39-cp39-manylinux_2_24_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.24+ x86-64 Details
extractnet-2.0.4-cp39-cp39-macosx_11_0_x86_64.whl CPython 3.9 CPython 3.9 macOS 11.0+ x86-64 Details
extractnet-2.0.4-cp39-cp39-macosx_10_15_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.15+ x86-64 Details
extractnet-2.0.4-cp38-cp38-manylinux_2_24_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.24+ x86-64 Details
extractnet-2.0.4-cp38-cp38-macosx_10_16_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.16+ x86-64 Details
extractnet-2.0.4-cp38-cp38-macosx_10_15_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.15+ x86-64 Details
extractnet-2.0.4-cp37-cp37m-manylinux_2_24_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.24+ x86-64 Details
extractnet-2.0.4-cp37-cp37m-macosx_10_16_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.16+ x86-64 Details
extractnet-2.0.4-cp37-cp37m-macosx_10_15_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64 Details
extractnet-2.0.4-cp36-cp36m-manylinux_2_24_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.24+ x86-64 Details
extractnet-2.0.4-cp36-cp36m-macosx_10_16_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.16+ x86-64 Details
extractnet-2.0.4-cp36-cp36m-macosx_10_15_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.15+ x86-64 Details
extractnet-2.0.4-cp36-cp36m-macosx_10_14_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64 Details

Total release size: 41.6 MB

Release files / extractnet-2.0.4.tar.gz

Download URL extractnet-2.0.4.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
dd39538df19c3b93278ff28952f2a571fda455c8e9935d08ed9e073332e833c6
BLAKE2b-256 checksum
How to use checksums
ee7e81e5571412d224bf40a541e73b380bb915ffddb2027716857b05723447a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp39-cp39-manylinux_2_24_x86_64.whl

Download URL extractnet-2.0.4-cp39-cp39-manylinux_2_24_x86_64.whl
Size 3.3 MB
Tags CPython 3.9 Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
3b755ecc3fde5720649d3b29a9f70a17665b73a1e447c0078813101a81ec60e6
BLAKE2b-256 checksum
How to use checksums
a3a72b86d86f0524b10ea0211648ef1cb5d198152a69f67dbbd37da5e5cb6b72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp39-cp39-macosx_11_0_x86_64.whl

Download URL extractnet-2.0.4-cp39-cp39-macosx_11_0_x86_64.whl
Size 1.8 MB
Tags CPython 3.9 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
f86f78e28daf22fbb54c9ef88c1db6f8e1c3fa11252caf4dcfaeb6a08efe012f
BLAKE2b-256 checksum
How to use checksums
b90f12ffd859978387db10940d852a444e59abfcda9692ebbb43f54ee21a2136
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp39-cp39-macosx_10_15_x86_64.whl

Download URL extractnet-2.0.4-cp39-cp39-macosx_10_15_x86_64.whl
Size 1.8 MB
Tags CPython 3.9 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
c6eb736fbfe97b7b61d0d298cfe7e64029037a6ea5564b27483e800211a2991a
BLAKE2b-256 checksum
How to use checksums
acc2eca425c1166569f346f13609e71a776f91ec54fba12bc66549d8bf114f67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp38-cp38-manylinux_2_24_x86_64.whl

Download URL extractnet-2.0.4-cp38-cp38-manylinux_2_24_x86_64.whl
Size 3.3 MB
Tags CPython 3.8 Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
b92efb37f3c09265c2f9a3700981fea51d0d322e3b80b57e010286ff5dc7ac27
BLAKE2b-256 checksum
How to use checksums
1c15bd9cff3fb6659449b08294029fdaf5ff923b74c3da9554ea3e877ec83c00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp38-cp38-macosx_10_16_x86_64.whl

Download URL extractnet-2.0.4-cp38-cp38-macosx_10_16_x86_64.whl
Size 1.8 MB
Tags CPython 3.8 macOS 10.16+ x86-64
SHA-256 checksum
How to use checksums
1c8ad1f9cad744c41de6537a8f3ad61e604630bf21340199ae6a57b77e2ddf86
BLAKE2b-256 checksum
How to use checksums
b2f6b9157fa2668c37078175d65cab92d04433a8b00424cecb260e41a21e667e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp38-cp38-macosx_10_15_x86_64.whl

Download URL extractnet-2.0.4-cp38-cp38-macosx_10_15_x86_64.whl
Size 1.8 MB
Tags CPython 3.8 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
83f069dd697ab3e7d88e79377933041c0a5641464ac1dc5c3c8410c7964f21d0
BLAKE2b-256 checksum
How to use checksums
a341f39ebd7970c2c4fc99a2f4eedddbac0b3dbe4a01a1edc13b69ef3d202fe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp37-cp37m-manylinux_2_24_x86_64.whl

Download URL extractnet-2.0.4-cp37-cp37m-manylinux_2_24_x86_64.whl
Size 3.2 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
69581b44010c021aa2142994ee99e39a066d6771801ba9915cbfc0f2362d9fc5
BLAKE2b-256 checksum
How to use checksums
78cb6c501e4591a926e0f86de9a5c396f05f6843632bfbd0b1123e4d2b289eb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp37-cp37m-macosx_10_16_x86_64.whl

Download URL extractnet-2.0.4-cp37-cp37m-macosx_10_16_x86_64.whl
Size 1.8 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.16+ x86-64
SHA-256 checksum
How to use checksums
275fe96c5a6f262d186e52e7a58f80e0d1bd95d6db09cd2f3bd42c3431215f64
BLAKE2b-256 checksum
How to use checksums
8d46a7f0b8f8ed05a18f19f3d8a7f14b1c33ae90be0d34c7fabe82b85b4b3948
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp37-cp37m-macosx_10_15_x86_64.whl

Download URL extractnet-2.0.4-cp37-cp37m-macosx_10_15_x86_64.whl
Size 1.8 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
30666d5eaa1f4a52cf3ed8275ab86b871aaee0f1ebfbea10d3d4ae54aeaee3db
BLAKE2b-256 checksum
How to use checksums
72a7cf96fba7c7b1556580a0e89feb30c31371380f50af2e3b8e2c549a72cf8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp36-cp36m-manylinux_2_24_x86_64.whl

Download URL extractnet-2.0.4-cp36-cp36m-manylinux_2_24_x86_64.whl
Size 3.2 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
1d6c1b06dceb9715805f940e9958774efb5d30dfded62dd9ca1cc4d9606ce2f1
BLAKE2b-256 checksum
How to use checksums
47a70ecac7e66c5bab59355a247f63c732ab82d135d0d991ac6a1e741e76a047
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp36-cp36m-macosx_10_16_x86_64.whl

Download URL extractnet-2.0.4-cp36-cp36m-macosx_10_16_x86_64.whl
Size 1.8 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.16+ x86-64
SHA-256 checksum
How to use checksums
f5feafe5301f9a2e89d929e734c1f6caeb1f1c11ac3faedfc63a95affd354baf
BLAKE2b-256 checksum
How to use checksums
da7c85927d4976418a6e1feeaaf270593caa9e44c51d1cf64101a4dd3549a567
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp36-cp36m-macosx_10_15_x86_64.whl

Download URL extractnet-2.0.4-cp36-cp36m-macosx_10_15_x86_64.whl
Size 1.8 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
0aa25206cb4251d3f9aa9235eb1bee222f30c20a7ba7c421cfa18b014932217b
BLAKE2b-256 checksum
How to use checksums
89a36cddf34f7b434b4680f64df5c3f5177f56be17bfd2c93cd5e73f34b24fae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release files / extractnet-2.0.4-cp36-cp36m-macosx_10_14_x86_64.whl

Download URL extractnet-2.0.4-cp36-cp36m-macosx_10_14_x86_64.whl
Size 12.7 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
9a72ce0ddba7302e78299afc91ff22fa8fb3cd36f2eed296116c659e0c53380b
BLAKE2b-256 checksum
How to use checksums
c815004939f9e6d4aae0da64dafb63f89b420cfcf8766fd45d5e99dd85d52bcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.6

Release history Release notifications | RSS feed

2.0.6

13 release files

This release

2.0.4 This release

14 release files

2.0.3

1 release file

1.0.4

6 release files

1.0.3

5 release files

1.0.2

9 release files

1.0.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page