{"id":19448099,"url":"https://github.com/scrapinghub/page_clustering","last_synced_at":"2025-02-25T08:52:29.130Z","repository":{"id":57450247,"uuid":"59656894","full_name":"scrapinghub/page_clustering","owner":"scrapinghub","description":"A simple algorithm for clustering web pages, suitable for crawlers","archived":false,"fork":false,"pushed_at":"2017-03-06T17:29:19.000Z","size":479,"stargazers_count":35,"open_issues_count":3,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-15T01:20:14.806Z","etag":null,"topics":["data-science"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scrapinghub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-25T11:17:45.000Z","updated_at":"2024-01-03T14:13:44.000Z","dependencies_parsed_at":"2022-09-10T00:30:59.122Z","dependency_job_id":null,"html_url":"https://github.com/scrapinghub/page_clustering","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapinghub%2Fpage_clustering","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapinghub%2Fpage_clustering/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapinghub%2Fpage_clustering/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapinghub%2Fpage_clustering/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scrapinghub","download_url":"https://codeload.github.com/scrapinghub/page_clustering/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240636664,"owners_count":19832922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science"],"created_at":"2024-11-10T16:24:04.659Z","updated_at":"2025-02-25T08:52:29.073Z","avatar_url":"https://github.com/scrapinghub.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Description [![Build Status](https://travis-ci.org/scrapinghub/page_clustering.svg?branch=master)](https://travis-ci.org/scrapinghub/page_clustering)\nA simple algorithm for clustering web pages.\nA wrapper around [KMeans](http://scikit-learn.org/stable/modules/generated/sklearn.cluster.MiniBatchKMeans.html#sklearn.cluster.MiniBatchKMeans).\nWeb pages are converted to vectors, where each vector entry is just the count of a given tag and class attribute.\nThe dimension of the vectors will change as new pages with new tags or class attributes arrive.\nAlso a simple outlier detection is available and enabled by default. This allows for rejecting web pages\nthat are highly improbable to belong to any cluster.\n\n# Install\n    pip install page_clustering\n\n# Usage\n    import page_clustering\n\n    clt = page_clustering.OnlineKMeans(n_clusters=5)\n    # `pages` must have been obtained somehow\n\tfor page in pages:\n\t    clt.add_page(page)\n\ty = clt.classify(new_page)\n\tfor page in more_pages:\n\t    clt.add_page(page)\n\ty = clt.classify(yet_another_page)\n\n# Demo\n    wget -r --quota=5M https://news.ycombinator.com\n    python demo.py news.ycombinator.com\n\n# Tests\n    cd tests\n    py.test\n\n# Algorithm\n\nThe first part, vectorization, transforms the web page to a vector. For example,\ntake the following page:\n\n```html\n\u003chtml\u003e\n\u003cbody\u003e\n\u003cul class=\"list1\"\u003e\n    \u003cli\u003eA\u003c/li\u003e\n\t\u003cli\u003eB\u003c/li\u003e\n\u003c/ul\u003e\n\u003cul class=\"list2\"\u003e\n    \u003cli\u003eY\u003c/li\u003e\n\t\u003cli\u003eZ\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nEach non-closing (tag, class) pair is mapped to a vector position and the number\nof times it appears in the document is the value of the vector at that position.\n\n| tag, class | position | count |\n|------------|----------|-------|\n| html       | 0        | 1     |\n| body       | 1        | 1     |\n| ul, list1  | 2        | 1     |\n| li         | 3        | 4     |\n| ul, list2  | 4        | 1     |\n\nThe vector is therefore `[1, 1, 1, 4, 1]`. This vector is normalized so that\nit's elements sum up to 1 and the final frequency vector is:\n`[0.125, 0.125, 0.125, 0.5, 0.125]`\n\nWhen a new page arrives it can be possible that new (tag, class) pairs appear.\nFor example imagine that this new page arrives:\n\n```html\n\u003chtml\u003e\n\u003cbody\u003e\n\u003cp\u003eAnother page with a paragraph tag \u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nThe new page would be mapped according to this table:\n\n| tag, class | position | count |\n|------------|----------|-------|\n| html       | 0        | 1     |\n| body       | 1        | 1     |\n| ul, list1  | 2        | 0     |\n| li         | 3        | 0     |\n| ul, list2  | 4        | 0     |\n| p          | 5        | 1     |\n\nThe vector for this page would be `[1, 1, 0, 0, 0, 1]`, and with normalization:\n`[0.33, 0.33, 0, 0, 0, 0.33]`.\n\nThe new vector has 6 dimensions, this means that the previous page vector needs\nto be extended accordingly with zeros to the right: `[0.125, 0.125, 0.125, 0.5, 0.125, 0]`.\n\nOnce all needed pages are vectorized, KMeans is applied.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrapinghub%2Fpage_clustering","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscrapinghub%2Fpage_clustering","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrapinghub%2Fpage_clustering/lists"}