Git Product home page Git Product logo

beautifulkuskus's Introduction

BeautifulKuskus

A minimal framework to extract content from HTML with BeautifulSoup and scikit-learn.

Basic usage

from beatifulkuskus import BeautifulKuskus

html="""
<html><body>
<h1>Header</h1>
<div id="content">
Ba <span class="a b c">boom</span>
</div>
<h5>Footer</h5>
</body></html>
"""
def id_is_content(x):
    return "content" in x.ids
kuskus = BeautifulKuskus(html)
print(str(kuskus.prune_by_func(id_is_content)))

SKlearn Model usage

from beatifulkuskus import BeautifulKuskus, DataPoint
import joblib # or any other model serialization format

def preprocess(data:DataPoint)->str:
    """This model would only consider the class names and ids"""
    # data is ("element", "tags", "classes", "ids", "text")
    classes = [" ".join(class_list) class_list for class_list on data.classes]
    return " ".join(data.ids) + " " + " ".join(classes)

model = joblib.load("content_model_on_ids_and_classes.joblib")
kuskus = BeautifulKuskus(html)
kuskus.prune_by_content_model(model, preprocess=preprocess)

beautifulkuskus's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.