VOOZH about

URL: https://apify.com/templates/python-standby

⇱ Standby Python project Β· Template Β· Apify


Back to template gallery

Language

πŸ‘ Image
python

Use cases

Starter

Integration

my_actor/main.py

my_actor/__main__.py

1"""Module defines the main entry point for the Apify Actor.
2
3Feel free to modify this file to suit your specific needs.
4
5To build Apify Actors, utilize the Apify SDK toolkit, read more at the official documentation:
6https://docs.apify.com/sdk/python
7"""
8
9from __future__ import annotations
10
11from http.server import HTTPServer, SimpleHTTPRequestHandler
12
13from apify import Actor
14
15
16classGetHandler(SimpleHTTPRequestHandler):
17"""A simple GET HTTP handler that will respond with a message."""
18
19defdo_GET(self)->None:
20"""Handle GET request and respond with a message."""
21# Handle Apify standby readiness probe
22# https://docs.apify.com/platform/actors/development/programming-interface/standby#readiness-probe
23if'x-apify-container-server-readiness-probe'in self.headers:
24 self.send_response(200)
25 self.end_headers()
26 self.wfile.write(b'ok')
27return
28
29 self.send_response(200)
30 self.end_headers()
31 self.wfile.write(b'Hello from Actor Standby!')
32
33
34asyncdefmain()->None:
35"""Define a main entry point for the Apify Actor.
36
37 This coroutine is executed using `asyncio.run()`, so it must remain an asynchronous function for proper execution.
38 Asynchronous execution is required for communication with Apify platform, and it also enhances performance in
39 the field of web scraping significantly.
40 """
41asyncwith Actor:
42# A simple HTTP server listening on Actor standby port.
43with HTTPServer(('', Actor.configuration.standby_port), GetHandler)as http_server:
44 http_server.serve_forever()

Python standby template

Start a new web scraping  project quickly and easily in Python with our Standby project template. It provides a basic structure for the Actor  with Apify SDK  and allows you to easily add your own functionality.

Included features

Resources

Crawlee + BeautifulSoup

Crawl and scrape websites using Crawlee and BeautifulSoup. Start from a URL and store results to your Apify dataset.

Starter

Empty Python project

Start with Apify SDK already set up, then build any features you need.

Starter

One‑Page HTML Scraper with BeautifulSoup

Scrape single page with provided URL with HTTPX and extract data from page's HTML with Beautiful Soup.

Starter

BeautifulSoup

Example of a web scraper that uses Python HTTPX to scrape HTML from URLs provided on input, parses it using BeautifulSoup and saves results to storage.

Playwright + Chrome

Crawler example that uses headless Chrome driven by Playwright to scrape a website. Headless browsers render JavaScript and can help when getting blocked.

Selenium + Chrome

Scraper example built with Selenium and headless Chrome browser to scrape a website and save the results to storage. A popular alternative to Playwright.

Already have a solution in mind?

Sign up for a free Apify account and deploy your code to the platform in just a few minutes! If you want a head start without coding it yourself, browse our Store of existing solutions.