Python Forum
Webscrape from my webpage and store in database and send to grafana
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Webscrape from my webpage and store in database and send to grafana
#1
Hi!

I want to webscrape a value from my webpage and send it to a database every 5 minutes and upload it to grafana.
I have done the webscrape python:

import requests
from bs4 import BeautifulSoup
URL = "http://ludvikasegel.com/wx/cloudbase.asp"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
molnbas = soup.find_all("div", class_="cloudbase")
print (molnbas[0].text.strip())
I am thinking of SQlite3 database.
I am not sure how to do it or how the python will look like.
I am also searching the internet about it.
Reply
#2
Have you found your answer?
Reply
#3
(Jul-12-2023, 07:09 AM)LoriSattler Wrote: Have you found your answer?

Well, I have got some help and have this code now:

import requests
import sqlite3
import datetime 

from bs4 import BeautifulSoup
URL = "http://ludvikasegel.com/wx/cloudbase.asp"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
molnbas = soup.find_all("div", class_="cloudbase")
print (molnbas[0].text.strip())


with sqlite3.connect('database.db') as con, open("d:\Cloudbase python\schema.sql") as f:
    con.executescript(f.read())


    desired_value = molnbas[0].text.strip()
    desired_value = molnbas[0].text.strip()
    timestamp = datetime.datetime.now().isoformat()  # timestamp, change to whatever you want

with sqlite3.connect("d:\Cloudbase python\database.db") as sqlite_connection:
    sqlite_connection.execute(
        "INSERT INTO table_name VALUES (?, ?)",
        (desired_value, timestamp)
    )
And I got values in SQlite database.
The question is if I am on the right track.
Next issue is to get the data to Grafana and plot a graph.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to access Windows Machine or Personal Certificate Store and send to web app seswho 0 1,647 Sep-14-2020, 04:57 PM
Last Post: seswho
  Trying to send input from html form to database SQLite3 RonnyGiezen 3 71,852 Dec-21-2019, 02:09 PM
Last Post: ibreeden
  Reading blob data from database by python and store it in .zip format Adityasi 2 6,639 Nov-18-2019, 05:22 PM
Last Post: ibreeden
  struggling with loop/webscrape zarize 4 2,499 Sep-27-2019, 08:44 AM
Last Post: zarize
  Store a python list of lists in a database to use for searches later on klllmmm 3 3,086 Jun-20-2019, 07:54 AM
Last Post: buran

Forum Jump:

User Panel Messages

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