Python Forum
Get Webcam Image from URL - Octoprint
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Webcam Image from URL - Octoprint
#1
Hello everyone
I am currently writing a script to output the current progress from my 3D printer. I use Octoprint to control the printer remotely. I want to take a picture of the webcam and wanted to access the URL of the webcam. The page is structured as follows:
Output:
<html> <head> <meta name="viewport" content="width=device-width, minimum-scale=0.1"><title>webcam (640×480)</title> </head> <body style="margin: 0px; background: #0e0e0e;"> <img style="-webkit-user-select: none;" src="http://octopi/webcam/?action=snapshot"> </body> </html>
My question is, how can I download the img element? I already tried google and only found solutions with absolute URLS.
Does anyone have an idea where I can start or what I could look at?

Thank you and greetings
Konff
Reply
#2
You parse out image url,the natural way with Python can be using BeautifulSoup and Requests.
A demo,and i use a image url that work to show download.
from bs4 import BeautifulSoup
import requests

html = '''\
<html>
    <head>
    <meta name="viewport" content="width=device-width, minimum-scale=0.1"><title>webcam (640×480)</title>
    </head>
    <body style="margin: 0px; background: #0e0e0e;">
        <img style="-webkit-user-select: none;" src="https://franceracing.fr/wp-content/uploads/2017/12/McLaren-Copier.jpeg">
    </body>
</html>'''

soup = BeautifulSoup(html, 'html.parser')
img_url = soup.find('img').get('src')
img = requests.get(img_url)
with open('McLaren.jpeg', 'wb') as f:
    f.write(img.content)
Reply
#3
Thanks @snippsat it's works !
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020