Create a page that loads infinitely with python

Completed form

Create a page that keeps outputting HTML endlessly and does not finish loading. Peek 2020-02-09 12-06.gif

Why did you make something like this?

I wanted to scrape a similar page, so for that test. I wrote the scraping method in this article.

Is it different from infinite scrolling?

Implementations of infinite scroll pages are often done in javascript, and the source is finite (ends), so you can get the source with curl or requests.get. On the other hand, the configuration introduced this time does not finish loading the source, so the usual curl and requests.get will time out.

environment

code

inf_page.py


import sys
import http.server
from http.server import SimpleHTTPRequestHandler
from http.server import BaseHTTPRequestHandler
from time import sleep 


class infiniteHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.send_header('Transfer-Encodeing', 'chunked')
        self.end_headers()
        inc = 0
        while(True):
            try:
                self.wfile.write(f"<p>Hello World ! {inc}</p>".encode("ascii"))
                self.wfile.flush()
                print("wrote")
                sleep(2)
                inc += 1
            except:
                break
        return


server_address = ('127.0.0.1', 8000)

infiniteHandler.protocol_version = "HTTP/1.1"
httpd = http.server.HTTPServer(server_address, infiniteHandler)

sa = httpd.socket.getsockname()
print("Serving HTTP on", sa[0], "port", sa[1], "...")
httpd.serve_forever()

See how it works

Browse [http: // localhost: 8000](http: // localhost: 8000) with your browser.

that's all. I wrote the scraping method in this article.

Recommended Posts

Create a page that loads infinitely with python
Create a new page in confluence with Python
Create a directory with python
Create a virtual environment with Python!
Create a Python function decorator with Class
[Python] A program that creates stairs with #
Build a blockchain with Python ① Create a class
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a word frequency counter with Python 3.4
[Python] Create a LineBot that runs regularly
A typed world that begins with Python
[LINE Messaging API] Create a BOT that connects with someone with Python
Create a frame with transparent background with tkinter [Python]
Create test data like that with Python (Part 1)
Create a Python module
Create a PDF file with a random page size
Create a virtual environment with conda in Python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
Create a color bar with Python + Qt (PySide)
Steps to create a Twitter bot with python
Python: Create a class that supports unpacked assignment
Create a decision tree from 0 with Python (1. Overview)
Create a color-specified widget with Python + Qt (PySide)
Create a Photoshop format file (.psd) with python
Create a Python environment
Create a Python console application easily with Click
Extract data from a web page with Python
[Python] Create a ValueObject with a complete constructor using dataclasses
Why not create a stylish table easily with Python?
Create a python development environment with vagrant + ansible + fabric
Create a chatbot that supports free input with Word2Vec
Create a Todo app with Django ③ Create a task list page
In Python, create a decorator that dynamically accepts arguments Create a decorator
A server that echoes data POSTed with flask / python
Create a Layer for AWS Lambda Python with Docker
[python] Create a date array with arbitrary increments with np.arange
A memo that I touched the Datastore with python
[Python] How to create a 2D histogram with Matplotlib
[Python] Create a Tkinter program distribution file with cx_Freeze
Create a fake Minecraft server in Python with Quarry
Create a company name extractor with python using JCLdic
Create a 2d CAD file ".dxf" with python [ezdxf]
Create a Wox plugin (Python)
Create a function in Python
Create a dictionary in Python
Create a homepage with django
Create a python numpy array
Make a fortune with Python
Create a heatmap with pyqtgraph
Create a discord bot that notifies unilaterally with python (use only requests and json)
Create an exe file that works in a Windows environment without Python with PyInstaller
Try to create a waveform (audio spectrum) that moves according to the sound with python
Create a web application that recognizes numbers with a neural network
A memo that reads data from dashDB with Python & Spark
Create a PythonBox that outputs with Random after PEPPER Input
[Python] Create a file & folder path specification screen with tkinter
Create a list in Python with all followers on twitter
Create a Mastodon bot with a function to automatically reply with Python