[Solved] record a web page using python [closed]


For opening a specific URL, you could use the module “webbrowser”:

import webbrowser

webbrowser.open('http://example.com')  # Go to example.com

For recording the page you could install the modules “opencv-python”, “numpy” and
“pyautogui”:

pip3 install opencv-python numpy pyautogui

And then use them all to get the final code, which could look something like this:

import cv2
import numpy as np
import os
import pyautogui
import webbrowser

webbrowser.open('http://example.com')  # Go to example.com

output = "video.avi"
img = pyautogui.screenshot()
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
#get info from img
height, width, channels = img.shape
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(output, fourcc, 20.0, (width, height))

for i in range(95):
    try:
        img = pyautogui.screenshot()
        image = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
        out.write(image)
        StopIteration(0.5)
    except KeyboardInterrupt:
        break

print("finished")
out.release()
cv2.destroyAllWindows()

The file should save as “video” and should be runnable. Your screen resolution should be detected automatically during a screenshot. If there are any issues within this code, feel free to tell it to me.

1

solved record a web page using python [closed]