#!/usr/bin/env python3
# requirements: * beautifulsoup4 (pip install beautifulsoup4)
#               * requests (pip install requests)
# works as of 2023-03-26, but will break if Rheinwerk Verlag 
# changes its website layout
import requests
import urllib.parse
from bs4 import BeautifulSoup

# parse HTML content using BeautifulSoup
siteurl = "https://www.rheinwerk-verlag.de/"
response = requests.get(siteurl)
dom = BeautifulSoup(response.content, 'html.parser')

# find the section that contains the eight new titles
new_titles_section = dom.find('div', class_ = 'topic_block-products')

# extract the eight new titles and their detail page links
articles = new_titles_section.find_all('article')
for article in articles:
    print('*', article['data-title'])
    link = article.find('a')['href']
    bookurl = urllib.parse.urljoin(siteurl, link)
    print(' ', bookurl)
