RAG और LLM pipelines के लिए Web scraping
Web pages को साफ़ Markdown में पाएँ, chunk और embed करने के लिए तैयार, menus, ads और scripts के बिना।
RAG के लिए Markdown क्यों
- Structure बना रहता है। Headings, lists, tables और code बने रहते हैं, इसलिए आप मनमाने character counts की जगह असली sections पर split कर सकते हैं।
- बहुत कम tokens। Menus, footers और ads हटने के बाद, main content आमतौर पर raw HTML के tokens का 3% से 24% होता है।
- Default रूप से main content। इसे
include_tagsऔरexclude_tagsसे और सीमित करें।
यह कैसे काम करता है
- URL भेजें
POST /v1/scrapeपर,response_format: "markdown"के साथ। - Chunk और embed करें Markdown को अपनी pipeline में। Spicrawl यह step नहीं करता।
- अपने schedule पर refresh करें वही URLs दोबारा भेजकर। कई pages के लिए 10,000 URLs तक की एक batch job इस्तेमाल करें।
curl -sS https://api.spicrawl.com/v1/scrape \
-H "Authorization: Bearer $SPICRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/docs/getting-started", "response_format": "markdown"}'import os, requests
H = {"Authorization": f"Bearer {os.environ['SPICRAWL_API_KEY']}"}
page = requests.post("https://api.spicrawl.com/v1/scrape", headers=H, json={
"url": "https://example.com/docs/getting-started",
"response_format": "markdown",
}, timeout=120)
markdown = page.text
# Split on headings, embed each chunk and store it: your pipeline, your tools.
chunks = markdown.split("\n## ")curl https://api.spicrawl.com/v1/batch \
-H "Authorization: Bearer $SPICRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "docs-refresh",
"urls": ["https://example.com/docs/a", "https://example.com/docs/b"],
"response_format": "markdown"
}'अपनी key SPICRAWL_API_KEY में रखें।
जिन sources को और चाहिए
- JavaScript pages:
js_render: trueset करें। देखें JavaScript websites की scraping। - PDFs: जब आप
markdownयाtextमाँगते हैं, तो plain text में parse किए जाते हैं। Scanned या encrypted PDFs में कोई text नहीं मिलता। - Login के पीछे के pages: उन accounts के लिए session इस्तेमाल करें जो आपके हैं या जिन्हें आप इस्तेमाल कर सकते हैं।
जानने लायक बातें
- Crawling नहीं। Spicrawl URLs नहीं ढूँढता और links follow नहीं करता। List भेजें, जैसे किसी sitemap से।
- Caching: Results डिफ़ॉल्ट रूप से 48 hours तक cached रहते हैं। नया fetch चाहिए तो
cache_ttl: 0set करें। Cache hit का bill उसी fetch जैसा लगता है जिसने उसे store किया था। - Pricing: beta के दौरान free। Plain page 1 credit का, JavaScript 3 का, full browser 8 का। Fail हुई requests की कीमत 0 है।
अक्सर पूछे जाने वाले सवाल
RAG के लिए Markdown क्यों इस्तेमाल करें?
Markdown headings, lists, tables और code रखता है, इसलिए आपका chunker असली structure पर split कर सकता है। यह raw HTML से काफ़ी छोटा भी है: menus, footers और ads हटाने के बाद main content आम तौर पर HTML के tokens का 3% से 24% होता है।
क्या Spicrawl content को chunk या embed करता है?
नहीं। Spicrawl साफ़ Markdown लौटाता है। उसे chunks में बाँटना, embed करना और vector database में store करना आपकी अपनी pipeline या framework में होता है।
मैं knowledge base के लिए कई pages कैसे scrape करूँ?
एक batch job में 10,000 URLs तक भेजें और results JSON Lines के रूप में पढ़ें। Spicrawl crawl नहीं करता: आप URLs की list भेजते हैं, जैसे किसी sitemap से।
क्या यह JavaScript pages और PDFs पढ़ सकता है?
हाँ। जिन pages का content browser में बनता है, उनके लिए js_render को true पर set करें। जब आप markdown या text माँगते हैं, तो PDF को plain text में parse किया जाता है; scanned या encrypted PDFs में कोई text नहीं मिलता।
मैं knowledge base को fresh कैसे रखूँ?
वही URLs अपने नियंत्रण वाले schedule पर दोबारा चलाएँ। Results default रूप से 48 घंटे के लिए cache होते हैं, इसलिए fresh fetch चाहिए तो cache_ttl को 0 सेट करें। Cache hit उसी तरह billed होता है जैसे उसे store करने वाला fetch।
इसकी कीमत कितनी है?
Beta के दौरान free: हर महीने 1,000 credits और credit card नहीं चाहिए। एक plain page की कीमत 1 credit है, JavaScript rendering की 3 और full browser की 8। Failed requests पर 0 लगता है।