Solution 1 :

import requests
from lxml import etree
from bs4 import BeautifulSoup
import pandas as pd

response = requests.get("https://www.boerse.de/historische-kurse/Daimler-Aktie/DE0007100000")

# storing content of page
src = response.content

# create BeatifulSoup Object based on src
soup = BeautifulSoup(src, 'html.parser')

tables = soup.find_all("table")

for table in tables:
    if "17.03.20" in table.text:
        df = pd.read_html(str(table))[0]
        row = df[df['Datum'] == "17.03.20"]

print (row)

Output:

print (row)
      Datum Erster Schluss    Hoch Tief  ... Schluss Volumen Veränderung Veränderung
0  17.03.20    23,77 23,98  24,81 21,57  ...    2398     4.290.555 5,64%       5,64%

[1 rows x 7 columns]

enter image description here

To check if date is a Sunday:

You need to convert the string to datetime object. Then you can either, convert into a string that states the day of the week. Or check for the numerical value (6 is for Sunday)

import datetime

dateStr = '17.03.20'
date_object = datetime.datetime.strptime(dateStr, '%d.%m.%y')


print (date_object.strftime('%A'))
print (date_object.weekday()) # Sunday = 6, Saturday = 5

Output:

Tuesday
1

Problem :

I want to save data from a table, which has been scraped from a website, into a SQLite Database. Here is what I was able to do so far. Preferrably i want to save a value into a variably and later load it into the database.

import requests
from lxml import etree
from bs4 import BeautifulSoup

response = requests.get("https://www.boerse.de/historische-kurse/Daimler-Aktie/DE0007100000")

# storing content of page
src = response.content

# create BeatifulSoup Object based on src
soup = BeautifulSoup(src, 'lxml')

tables = soup.find_all("tr")


"""for table in tables:
    if "17.03.20" in table.text:
        table = table.text
        table = etree.HTML(table)
        rows = iter(table)
        for row in rows:
            values = [col.text for col in row]
            print(values)"""

for table in tables:
    if "17.03.20" in table.text:
        print(table)

Comments

Comment posted by chitown88

so what’s your question? What are you trying to extract? What is your expected output here?

Comment posted by Hendrik Niemax

If you look at the website, i want to have the first column/value for the date 17.03.20 (first row in table) saved in a variable and later put into a SQLite Database.

Comment posted by Hendrik Niemax

And how do i get the 23,77 for example into a variable?

Comment posted by chitown88

value = row.loc[0,’Erster Schluss’].split()[0]

Comment posted by Hendrik Niemax

What is the ‘Erster Schluss’ for? If i want the column next to it ‘Schluss’ should be the indicator right?

Comment posted by chitown88

It’s little tricky here. Normally, you would be correct, but how the html is layed out, and since you were asking for

Comment posted by Hendrik Niemax

Ah ok thank got it. And how do i get from other dates? 17.03.20 seems to be the only one to work now. I cant just replace the date

By