Keyword-driven web scraping pipeline (Serper + OpenAI).
Project description
kazparserbot
Keyword-driven scraping pipeline using Serper (search + scrape) and OpenAI.
Install
pip install kazparserbot
Required environment variables
Put these in your environment or in a local .env file (see .env.template):
SERPER_API_KEY(required)OPENAI_API_KEY(recommended)
Library usage (recommended)
Basic usage (sync)
from kazparserbot import KazParserBot
bot = KazParserBot.from_env()
result = bot.scrape_keywords_sync(
["keyword1", "keyword2"],
google_results_to_get_per_query=10,
top_results_to_get=5,
queries_to_generate_per_keyword=3,
)
With image retrieval enabled
This downloads images to an imgs/ folder in the current working directory and returns image metadata under the __imgs__ key.
from kazparserbot import KazParserBot
bot = KazParserBot.from_env()
result = bot.scrape_keywords_sync(
["keyword1", "keyword2"],
collect_imgs_and_context=True,
)
imgs = result.get("__imgs__", [])
Public API
kazparserbot.KazParserBot
Create an instance:
KazParserBot.from_env(...)dotenv_path: path to a.envfile (optional)load_dotenv_first: whether to load.envbefore reading env vars (defaultTrue)gpt_concurrency: max in-flight OpenAI requests (default100)serper_concurrency: max in-flight Serper requests (default100)http_timeout_s: per-request HTTP timeout in seconds for Serper + image fetching (default30.0)
Core methods:
-
await bot.scrape_keywords(keywords, *, google_results_to_get_per_query=10, top_results_to_get=5, queries_to_generate_per_keyword=3, collect_imgs_and_context=False)keywords: list of keywords to processgoogle_results_to_get_per_query: how many Serper search results to fetch per querytop_results_to_get: how many results to keep per language (RU + KK); internally the model choosestop_results_to_get * 2queries_to_generate_per_keyword: number of RU queries and KK queries to generate per keywordcollect_imgs_and_context: ifTrue, downloads images and extracts nearby text context- Returns
dict[str, list[dict]]. When image retrieval is enabled, images are stored under__imgs__as a list of dicts containing:url,img_url,context_text_before,context_text_after,file_path
-
bot.scrape_keywords_sync(keywords, **kwargs)- Synchronous wrapper around
scrape_keywords(...)(same kwargs)
- Synchronous wrapper around
-
bot.scrape_from_files(*, keywords_json, output_json, google_results_to_get_per_query=10, top_results_to_get=5, queries_to_generate_per_keyword=3, collect_imgs_and_context=False)keywords_json: path to a JSON file containing a list of keywordsoutput_json: path to write results JSON
kazparserbot.Settings
Settings.from_env(dotenv_path=None, load_dotenv_first=True)- Validates
SERPER_API_KEYis present and readsOPENAI_API_KEYif set.
- Validates
CLI usage
After installing:
kazparserbot keywords.json output.json \
--google_results_to_get_per_query=10 \
--top_results_to_get=5 \
--queries_to_generate_per_keyword=3 \
--collect_imgs_and_context=True
The legacy entrypoint is still available:
python scrap_by_keywords.py keywords.json output.json --collect_imgs_and_context=True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kazparserbot-0.1.2.tar.gz.
File metadata
- Download URL: kazparserbot-0.1.2.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
632275a811d2f4c7814d860a01f76df36a9ed2c9bfb4b98cd915e4e884788a7b
|
|
| MD5 |
ecf65111ce3ced86be8f424d7531f738
|
|
| BLAKE2b-256 |
8d4b769dbed98c25e4e1a25c8bbb130d083fa32613c97e3453683b84befccfef
|
File details
Details for the file kazparserbot-0.1.2-py3-none-any.whl.
File metadata
- Download URL: kazparserbot-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0519bf886446cfecad8fc873bb82334d635f6fa6e0ca8d9188c6e16d974373b
|
|
| MD5 |
a3980f8725aa2344524577a74cc1af2e
|
|
| BLAKE2b-256 |
ab6be5345dfc68db347df33316d74702ad44ada50f7ef4333c29c915280e318d
|