Skip to main content

Keyword-driven web scraping pipeline (Serper + OpenAI).

Project description

Keyword Processor with Serper.dev and GPT

Description

This script:

  1. Expands each keyword into 2 * queries_to_generate_per_keyword queries (the first half in Russian, the second half in Kazakh).
  2. Uses serper.dev to retrieve search results for these queries.
  3. De-duplicates and merges those results.
  4. Asks GPT to pick the top top_results_to_get results for each keyword.
  5. Scrapes those pages via serper.dev to get full text.
  6. Outputs everything to a JSON file.

Setup

  • Python 3.11+
  • poetry install
  • poetry shell
  • Copy .env.template and fill in the OpenAI and Serper keys

Usage

  1. Create a JSON file with a list of keywords, for example:
["Dimash Qudaibergen", "Apple Inc"]
  1. Run:
python scrap_by_keywords.py 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
  • google_results_to_get_per_query controls how many results to retrieve for each query.
  • top_results_to_get is how many of those results to parse further.
  • queries_to_generate_per_keyword is how many queries to generate in Russian (and then again in Kazakh), so total is double that.
  • collect_imgs_and_context controls whether to collect images and context for each result after the main results are collected. Will output <output_json>_imgs.json and imgs folder with images. Json will contain list of dicts with 'url', 'img_url', 'context_text_before', 'context_text_after', 'file_path' fields. Only keep images > N pixels to prevent getting trash, technical imgs, headers, etc.
  1. The output will be in path/to/output.json, for instance:
{
  "Dimash Qudaibergen": [
    {
      "url": "...",
      "google_snippet": "...",
      "full_text": "..."
    },
    ...
  ],
  ...
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kazparserbot-0.1.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kazparserbot-0.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file kazparserbot-0.1.1.tar.gz.

File metadata

  • Download URL: kazparserbot-0.1.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for kazparserbot-0.1.1.tar.gz
Algorithm Hash digest
SHA256 86f3e729cbc1ad24f20a7d5e6f665847883cfa843f66b1cddbdc22cb0fa6d032
MD5 8c7357308c5d480dc37deabe1774f28b
BLAKE2b-256 bf51ffd4482a6c31122cb1415aefa0cc7816e0ce45b6d6361cdfa5bef3fc79f2

See more details on using hashes here.

File details

Details for the file kazparserbot-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kazparserbot-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for kazparserbot-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4cfa0576112121dfacdecb9ac57dc9c290d21bcab3fd75e4bad7c46297dbfcb
MD5 8947895db743bf2ad6592dc65f5ae61d
BLAKE2b-256 c1a6c51eb34ca6a9b36953dc5af4fa3085322973590cab2e2154ec91725ff509

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page