From 7247576022d0a87860341e7df178b7fcdbb1416f Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Mon, 8 Jan 2024 14:15:49 +0100 Subject: [PATCH] :sparkles: signatures is now scraped! Co-authored-by: haraldnilsen Signed-off-by: Sindre Kjelsrud --- main.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 4af8063..576fe50 100644 --- a/main.py +++ b/main.py @@ -48,10 +48,25 @@ def fetch_all_info(url): # Extracting the question and answer sporsmal = html.css_first('div.article-text').text() + # Check if the element exists before accessing its text + signatur_div = html.css_first('div.signatur') + signatur = "" + if signatur_div: + signaturTxt = signatur_div.text() + # Remove "Med vennlig hilsen" or "Vennlig hilsen" + signaturTxt = signaturTxt.replace("Med vennlig hilsen", "").replace("Vennlig hilsen", "").strip() + # Check if the text is empty after removal + if signaturTxt: + signatur = signaturTxt + else: + signatur = "Null signatur" + else: + signatur = "Null signatur" + # Create array of results #result = [sporsmal, svar, signatur] - return sporsmal + return signatur studenterspor_url = "https://www.studenterspor.no/ajax_handler.php" urls = fetch_question_url(studenterspor_url)