Got it — you want to programmatically download all pages whose URL starts with example.com/share from Common Crawl, without using AWS (no S3 or Athena). This is doable because Common Crawl publishes its index (CDX API) and WARC files publicly.
Here’s a step-by-step guide and Python code:
1️⃣ Use the Common Crawl Index (CDX API)
Common Crawl provides a free index API of all crawled URLs:
perlCopiar códigohttps://index.commoncrawl.org/CC-MAIN-YYYY-WW-index
You can query it with:
pgsqlCopiar códigohttps://index.commoncrawl.org/CC-MAIN-YYYY-WW-index?url=example.com/share*&output=json
Replace YYYY-WW with a crawl number (like CC-MAIN-2024-33).
This returns JSON lines with metadata including the WARC file and byte offsets you’ll need to retrieve the raw page.
2️⃣ Python code to query CDX API & download pages
pythonCopiar códigoimport requests
import json
from warcio.archiveiterator import ArchiveIterator
crawl = "CC-MAIN-2024-33" # latest crawl snapshot
2. Query CDX API for all URLs starting with example.com/share
query_url = f"https://index.commoncrawl.org/{crawl}-index?url=example.com/share*&output=json"
print(f"Querying {query_url} ...")
resp = requests.get(query_url)
resp.raise_for_status()
records = [json.loads(line) for line in resp.text.splitlines()]
print(f"Found {len(records)} records")
3. Download each WARC record and extract the HTML
for rec in records:
warc_filename = rec['filename']
offset = int(rec['offset'])
length = int(rec['length'])
url = rec['url']
warc_url = f"https://data.commoncrawl.org/{warc_filename}"
headers = {"Range": f"bytes={offset}-{offset+length-1}"}
warc_resp = requests.get(warc_url, headers=headers, stream=True)
warc_resp.raise_for_status()
# Use warcio to parse WARC
for record in ArchiveIterator(warc_resp.raw, arc2warc=True):
if record.rec_type == 'response':
html = record.content_stream().read()
# Do something with html, like save to file
filename = url.replace("https://","").replace("http://","").replace("/","_")
with open(f"{filename}.html", "wb") as f:
f.write(html)
print(f"Saved {url}")
3️⃣ Explanation
We first get a list of all snapshots with:
pgsqlCopiar códigohttps://index.commoncrawl.org/collinfo.json
For each crawl you care about, query URLs with url=example.com/share*.
Each record gives you a filename (WARC path), offset, and length.
You make a ranged HTTP request to https://data.commoncrawl.org/ to download that part of the WARC file.
Use warcio to parse the WARC record and extract the page content.
This approach does not require AWS credentials — everything is public HTTPS.
4️⃣ Install requirements:
bashCopiar códigopip install requests warcio
Do you want me to include code that automatically loops through all Common Crawl snapshots (not just one crawl)? (It’s easy to add.)