# comcrawl
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/michaelharms/comcrawl/CI)
[![codecov](https://codecov.io/gh/michaelharms/comcrawl/branch/master/graph/badge.svg?token=FEw4KEcpRm)](https://codecov.io/gh/michaelharms/comcrawl)
![GitHub](https://img.shields.io/github/license/michaelharms/comcrawl)
_comcrawl_ is a python package for easily querying and downloading pages from [commoncrawl.org](https://commoncrawl.org).
## Introduction
I was inspired to make _comcrawl_ by reading this [article](https://www.bellingcat.com/resources/2015/08/13/using-python-to-mine-common-crawl/).
**Note:** I made this for personal projects and for fun. Thus this package is intended for use in small to medium projects, because it is not optimized for handling gigabytes or terrabytes of data. You might want to check out [cdx-toolkit](https://pypi.org/project/cdx-toolkit/) or [cdx-index-client](https://github.com/ikreymer/cdx-index-client) in such cases.
### What is Common Crawl?
The Common Crawl project is an _"open repository of web crawl data that can be accessed and analyzed by anyone"_.
It contains billions of web pages and is often used for NLP projects to gather large amounts of text data.
Common Crawl provides a [search index](https://index.commoncrawl.org), which you can use to search for certain URLs in their crawled data.
Each search result contains a link and byte offset to a specific location in their [AWS S3 buckets](https://commoncrawl.s3.amazonaws.com/cc-index/collections/index.html) to download the page.
### What does _comcrawl_ offer?
_comcrawl_ simplifies this process of searching and downloading from Common Crawl by offering a simple API interface you can use in your python program.
## Installation
_comcrawl_ is available on PyPI.
Install it via pip by running the following command from your terminal:
```
pip install comcrawl
```
## Usage
### Basic
The HTML for each page will be available as a string in the 'html' key in each results dictionary after calling the `download` method.
```python
from comcrawl import IndexClient
client = IndexClient()
client.search("reddit.com/r/MachineLearning/*")
client.download()
first_page_html = client.results[0]["html"]
```
### Multithreading
You can leverage multithreading while searching or downloading by specifying the number of threads you want to use.
Please keep in mind to not overdo this, so you don't put too much stress on the Common Crawl servers (have a look at [Code of Conduct](#code-of-conduct)).
```python
from comcrawl import IndexClient
client = IndexClient()
client.search("reddit.com/r/MachineLearning/*", threads=4)
client.download(threads=4)
```
### Removing duplicates & Saving
You can easily combine this package with the [pandas](https://github.com/pandas-dev/pandas) library, to filter out duplicate results and persist them to disk:
```python
from comcrawl import IndexClient
import pandas as pd
client = IndexClient()
client.search("reddit.com/r/MachineLearning/*")
client.results = (pd.DataFrame(client.results)
.sort_values(by="timestamp")
.drop_duplicates("urlkey", keep="last")
.to_dict("records"))
client.download()
pd.DataFrame(client.results).to_csv("results.csv")
```
The urlkey alone might not be sufficient here, so you might want to write a function to compute a custom id from the results' properties for the removal of duplicates.
### Searching subsets of Indexes
By default, when instantiated, the `IndexClient` fetches a list of currently available Common Crawl indexes to search. You can also restrict the search to certain Common Crawl Indexes, by specifying them as a list.
```python
from comcrawl import IndexClient
client = IndexClient(["2019-51", "2019-47"])
client.search("reddit.com/r/MachineLearning/*")
client.download()
```
### Logging HTTP requests
When debugging your code, you can enable logging of all HTTP requests that are made.
```python
from comcrawl import IndexClient
client = IndexClient(verbose=True)
client.search("reddit.com/r/MachineLearning/*")
client.download()
```
## Code of Conduct
When accessing Common Crawl, please beware these guidelines posted by one of the Common Crawl maintainers:
https://groups.google.com/forum/#!msg/common-crawl/3QmQjFA_3y4/vTbhGqIBBQAJ
Raw data
{
"_id": null,
"home_page": "https://github.com/michaelharms/comcrawl",
"name": "comcrawl",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6,<4.0",
"maintainer_email": "",
"keywords": "commoncrawl,machine-learning,nlp,data,common-crawl,scraping,deep-learning,training-dataset",
"author": "Michael Harms",
"author_email": "michaelharms95@icloud.com",
"download_url": "https://files.pythonhosted.org/packages/7c/46/0c519595db0a5e217ab43b0755f7d8d3be305e0da98caee31df0454d20b5/comcrawl-1.0.2.tar.gz",
"platform": "",
"description": "# comcrawl\n\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/michaelharms/comcrawl/CI)\n[![codecov](https://codecov.io/gh/michaelharms/comcrawl/branch/master/graph/badge.svg?token=FEw4KEcpRm)](https://codecov.io/gh/michaelharms/comcrawl)\n![GitHub](https://img.shields.io/github/license/michaelharms/comcrawl)\n\n_comcrawl_ is a python package for easily querying and downloading pages from [commoncrawl.org](https://commoncrawl.org).\n\n## Introduction\n\nI was inspired to make _comcrawl_ by reading this [article](https://www.bellingcat.com/resources/2015/08/13/using-python-to-mine-common-crawl/).\n\n**Note:** I made this for personal projects and for fun. Thus this package is intended for use in small to medium projects, because it is not optimized for handling gigabytes or terrabytes of data. You might want to check out [cdx-toolkit](https://pypi.org/project/cdx-toolkit/) or [cdx-index-client](https://github.com/ikreymer/cdx-index-client) in such cases.\n\n### What is Common Crawl?\n\nThe Common Crawl project is an _\"open repository of web crawl data that can be accessed and analyzed by anyone\"_.\nIt contains billions of web pages and is often used for NLP projects to gather large amounts of text data.\n\nCommon Crawl provides a [search index](https://index.commoncrawl.org), which you can use to search for certain URLs in their crawled data.\nEach search result contains a link and byte offset to a specific location in their [AWS S3 buckets](https://commoncrawl.s3.amazonaws.com/cc-index/collections/index.html) to download the page.\n\n### What does _comcrawl_ offer?\n\n_comcrawl_ simplifies this process of searching and downloading from Common Crawl by offering a simple API interface you can use in your python program.\n\n## Installation\n\n_comcrawl_ is available on PyPI.\n\nInstall it via pip by running the following command from your terminal:\n\n```\npip install comcrawl\n```\n\n## Usage\n\n### Basic\n\nThe HTML for each page will be available as a string in the 'html' key in each results dictionary after calling the `download` method.\n\n```python\nfrom comcrawl import IndexClient\n\nclient = IndexClient()\n\nclient.search(\"reddit.com/r/MachineLearning/*\")\nclient.download()\n\nfirst_page_html = client.results[0][\"html\"]\n```\n\n### Multithreading\n\nYou can leverage multithreading while searching or downloading by specifying the number of threads you want to use.\n\nPlease keep in mind to not overdo this, so you don't put too much stress on the Common Crawl servers (have a look at [Code of Conduct](#code-of-conduct)).\n\n```python\nfrom comcrawl import IndexClient\n\nclient = IndexClient()\n\nclient.search(\"reddit.com/r/MachineLearning/*\", threads=4)\nclient.download(threads=4)\n```\n\n### Removing duplicates & Saving\n\nYou can easily combine this package with the [pandas](https://github.com/pandas-dev/pandas) library, to filter out duplicate results and persist them to disk:\n\n```python\nfrom comcrawl import IndexClient\nimport pandas as pd\n\nclient = IndexClient()\nclient.search(\"reddit.com/r/MachineLearning/*\")\n\nclient.results = (pd.DataFrame(client.results)\n .sort_values(by=\"timestamp\")\n .drop_duplicates(\"urlkey\", keep=\"last\")\n .to_dict(\"records\"))\n\nclient.download()\n\npd.DataFrame(client.results).to_csv(\"results.csv\")\n```\n\nThe urlkey alone might not be sufficient here, so you might want to write a function to compute a custom id from the results' properties for the removal of duplicates.\n\n### Searching subsets of Indexes\n\nBy default, when instantiated, the `IndexClient` fetches a list of currently available Common Crawl indexes to search. You can also restrict the search to certain Common Crawl Indexes, by specifying them as a list.\n\n```python\nfrom comcrawl import IndexClient\n\nclient = IndexClient([\"2019-51\", \"2019-47\"])\nclient.search(\"reddit.com/r/MachineLearning/*\")\nclient.download()\n```\n\n### Logging HTTP requests\n\nWhen debugging your code, you can enable logging of all HTTP requests that are made.\n\n```python\nfrom comcrawl import IndexClient\n\nclient = IndexClient(verbose=True)\nclient.search(\"reddit.com/r/MachineLearning/*\")\nclient.download()\n```\n\n## Code of Conduct\n\nWhen accessing Common Crawl, please beware these guidelines posted by one of the Common Crawl maintainers:\n\nhttps://groups.google.com/forum/#!msg/common-crawl/3QmQjFA_3y4/vTbhGqIBBQAJ\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A python utility for downloading Common Crawl data.",
"version": "1.0.2",
"project_urls": {
"Homepage": "https://github.com/michaelharms/comcrawl",
"Repository": "https://github.com/michaelharms/comcrawl"
},
"split_keywords": [
"commoncrawl",
"machine-learning",
"nlp",
"data",
"common-crawl",
"scraping",
"deep-learning",
"training-dataset"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "df1911fac3419c0da637abc9e99b2f18953813f7d77c9e5916e93d7a5aba3845",
"md5": "ae35b6a43b11802b887c87d056ce7fc0",
"sha256": "2a9d299f88b8deb877ede94fa67cc8ecf300d1206fd225488037f8b70cd28ca8"
},
"downloads": -1,
"filename": "comcrawl-1.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ae35b6a43b11802b887c87d056ce7fc0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6,<4.0",
"size": 10012,
"upload_time": "2020-07-28T18:25:56",
"upload_time_iso_8601": "2020-07-28T18:25:56.364208Z",
"url": "https://files.pythonhosted.org/packages/df/19/11fac3419c0da637abc9e99b2f18953813f7d77c9e5916e93d7a5aba3845/comcrawl-1.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7c460c519595db0a5e217ab43b0755f7d8d3be305e0da98caee31df0454d20b5",
"md5": "a67d1d3efc74ddfb7a6d20982b556e43",
"sha256": "a542db1b7cc05f65bfcef012d0dbf838331aebd7876fb9764734da788d608433"
},
"downloads": -1,
"filename": "comcrawl-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "a67d1d3efc74ddfb7a6d20982b556e43",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6,<4.0",
"size": 8941,
"upload_time": "2020-07-28T18:25:57",
"upload_time_iso_8601": "2020-07-28T18:25:57.297791Z",
"url": "https://files.pythonhosted.org/packages/7c/46/0c519595db0a5e217ab43b0755f7d8d3be305e0da98caee31df0454d20b5/comcrawl-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-07-28 18:25:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "michaelharms",
"github_project": "comcrawl",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "comcrawl"
}