import requests
from bs4 import BeautifulSoup
import time
import schedule


def access():
    url = 'https://f...content-available-to-author-only...e.com/c/marketplace/sales-ads/'
    try:
        r = requests.get(url)
        r.raise_for_status()
        open('sales-ads.html', 'wb').write(r.content)
    except requests.exceptions.HTTPError as err:
        print(err)


def extraction():
    with open('sales-ads.html') as file:
        src = file.read()
        soup = BeautifulSoup(src, 'lxml')
    with open('topics.txt', 'w') as f:
        topic_names = soup.find_all('a', class_='title raw-link raw-topic-link')
        for item in topic_names:
            item_text = item.text
            item_url = item.get('href')
            print(f"{item_text}: {item_url}", file=f)


schedule.every(5).seconds.do(access)
schedule.every(5).seconds.do(extraction)

while True:
    schedule.run_pending()
    time.sleep(1)
