Skip to main content

ScrapingBee Python SDK

Project description

ScrapingBee Python SDK

lint-test-publish version python

ScrapingBee is a web scraping API that handles headless browsers and rotates proxies for you. The Python SDK makes it easier to interact with ScrapingBee's API.

Installation

You can install ScrapingBee Python SDK with pip.

pip install scrapingbee

Usage

The ScrapingBee Python SDK is a wrapper around the requests library.

Signup to ScrapingBee to get your API key and some free credits to get started.

Table of Contents


HTML API

The HTML API allows you to scrape any webpage and get the HTML content.

Basic Request

from scrapingbee import ScrapingBeeClient

client = ScrapingBeeClient(api_key='YOUR-API-KEY')

response = client.html_api(
    'https://www.scrapingbee.com',
    params={
        'render_js': False,
    }
)

print(response.content)

Making a POST request

response = client.html_api(
    'https://httpbin.org/post',
    method='POST',
    data={
        'key': 'value'
    }
)

Google Search API

Scrape Google search results in real-time.

response = client.google_search(
    search='web scraping tools',
    params={
        'language': 'en',
        'country_code': 'us',
        'nb_results': 10
    }
)

print(response.json())

Fast Search API

Lightweight Google search results in under a second.

response = client.fast_search(
    search='pizza in new york',
    params={
        'country_code': 'us',
        'language': 'en',
        'page': 1
    }
)

print(response.json())

Amazon API

Scrape Amazon search results, product details, and pricing.

Amazon Search

response = client.amazon_search(
    query='laptop',
    params={
        'domain': 'com',
        'language': 'en',
        'pages': 1
    }
)

print(response.json())

Amazon Product

response = client.amazon_product(
    query='B0D2Q9397Y',  # ASIN
    params={
        'domain': 'com'
    }
)

print(response.json())

Amazon Pricing

response = client.amazon_pricing(
    asin='B0DPDRNSXV',
    params={
        'domain': 'com',
        'light_request': True
    }
)

print(response.json())

Walmart API

Scrape Walmart search results and product details.

Walmart Search

response = client.walmart_search(
    query='laptop',
    params={
        'sort_by': 'best_match',
        'device': 'desktop'
    }
)

print(response.json())

Walmart Product

response = client.walmart_product(
    product_id='123456789',
    params={
        'device': 'desktop'
    }
)

print(response.json())

YouTube API

Scrape YouTube search results, video metadata, and subtitles.

YouTube Search

response = client.youtube_search(
    search='web scraping tutorial',
    params={
        'sort_by': 'relevance',
        'type': 'video'
    }
)

print(response.json())

YouTube Metadata

response = client.youtube_metadata(video_id='dQw4w9WgXcQ')
print(response.json())

YouTube Subtitles

response = client.youtube_subtitles(
    video_id='dQw4w9WgXcQ',
    params={
        'language': 'en',
        'subtitle_origin': 'uploader_provided'
    }
)
print(response.json())

ChatGPT API

Use ChatGPT with optional web search.

response = client.chatgpt(
    prompt='What is web scraping?',
    params={
        'search': True,
        'country_code': 'us'
    }
)

print(response.json())

Gemini API

Send prompts to Gemini and receive AI-generated responses.

response = client.gemini(
    prompt='Best programming languages for data science',
    params={
        'country_code': 'us',
        'add_html': False
    }
)

print(response.json())

Usage API

Check your API credit usage.

response = client.usage()
print(response.json())
# {
#     "max_api_credit": 8000000,
#     "used_api_credit": 1000023,
#     "max_concurrency": 200,
#     "current_concurrency": 1
# }

Legacy Methods (Deprecated)

The get() and post() methods are deprecated and will be removed in a future version. Please use html_api() instead.

# Deprecated
client.get(url, params={...})

# Use instead
client.html_api(url, method='GET', params={...})

Screenshot

Here is a little example on how to retrieve and store a screenshot from the ScrapingBee blog.

from scrapingbee import ScrapingBeeClient

client = ScrapingBeeClient(api_key='YOUR-API-KEY')

response = client.html_api(
    'https://www.scrapingbee.com/',
    params={
        'screenshot': True,
        'screenshot_full_page': True,
        'window_width': 375,
    }
)

with open('screenshot.png', 'wb') as f:
    f.write(response.content)

Retries

The client includes a retry mechanism for 5XX responses.

client.html_api(url, params={...}, retries=5)

Using ScrapingBee with Scrapy

Scrapy is the most popular Python web scraping framework. You can easily integrate ScrapingBee's API with the Scrapy middleware.

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

scrapingbee-2.1.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

scrapingbee-2.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file scrapingbee-2.1.0.tar.gz.

File metadata

  • Download URL: scrapingbee-2.1.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for scrapingbee-2.1.0.tar.gz
Algorithm Hash digest
SHA256 cbe737dc7867f1cae2cecd3757f37dd7ed76768cc571cd3f64a7af5f46ebc9ba
MD5 c4630e9b2d398d63286aa4535a1f9748
BLAKE2b-256 7f97655c63d0dbd47232e8842a73427bad28df335f4944a0849d1d50372053e9

See more details on using hashes here.

File details

Details for the file scrapingbee-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: scrapingbee-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for scrapingbee-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec109005160d7529eb02b5c931b9ad1cbbbf2b5c03942baf5745876c409dc1a8
MD5 51cb68a793c754666d66ff57edee6dde
BLAKE2b-256 786c78162214431710b18a9fc231ca916433f8551813764e4cf7c61a8f5078bd

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