Why doesn't this function return the same output in both situations(webscraping project)?

import requests
import re
from bs4 import BeautifulSoup

#The website I like to get, converts the contents of the web page to lxml format
base_url = "https://festivalfans.nl/event/dominator-festival"
url = requests.get(base_url)
soup = BeautifulSoup(url.content, "lxml")

#Modifies the given string to look visually good. Like this:
#['21 / JulZaterdag2018'] becomes 21 Jul 2018
def remove_char(string):
    #All blacklisted characters and words
    blacklist = ["/", "[", "]", "'", "Maandag", "Dinsdag", "Woensdag",
                 "Donderdag", "Vrijdag", "Zaterdag", "Zondag"]

    #Replace every blacklisted character with white space
    for char in blacklist:
        string = string.replace(char,' ')

    #Replace more than 2 consecutive white spaces
    string = re.sub("\s\s+", " ", string)


#Gets the date of the festival I'm interested in
def get_date_info():
    #Makes a list for the data
    raw_info = []

    #Adds every "div" with a certain name to list, and converts it to text
    for link in soup.find_all("div", {"class": "event-single-data"}):
        raw_info.append(link.text)

    #Converts list into string, because remove_char() only accepts strings    
    raw_info = str(raw_info)

    #Modifies the string as explained above
    final_date = remove_char(raw_info)

    #Prints the date in this format: 21 Jul 2018(example)
    print(final_date)


get_date_info()

Hi there! So I'm currently working on a little webscraping project. I thought I had a good idea and I wanted to get more experienced with Python. What it basically does is it gets festival information like date, time and price and puts it in a little text file. I'm using BeautifulSoup to navigate and edit the web page. Link is down there!

But now I'm kinda running into a problem. I can't figure out what's wrong. Maybe I'm totally looking over it. So when I run this program it should give me this: 21 Jul 2018. But instead it returns 'None'. For some reason every character in the string gets removed.

I tried running remove_char() on its own, with the same list(converted it to string first) as input. This worked perfectly. It returned "21 Jul 2018" like it was supposed to do. So I'm quite sure the error is not in this function.

So somehow I'm missing something. Maybe it has to do with BeautifulSoup and how it handles things?

Hope someone can help me out!

BeautifulSoup: https://www.crummy.com/software/BeautifulSoup/bs4/doc/

Web page: https://festivalfans.nl/event/dominator-festival

You forgot to return the value in the remove_char() function. That's it!

Why Trump doesn't want to wear a mask - CNN, It's no surprise that President Donald Trump says he won't follow CDC recommendations to wear a mask to stop the spread of coronavirus,  To find out why, Menachery has been giving mice at his Texas lab SARS — which is a very close cousin to the new coronavirus. Baby mice at his lab have shaken off the infection, while the older

Neither of your functions has a return statement, and so return None by default. remove_char() should end with return string for example.

Why Johnny Doesn't Flap: NT is OK!: Morton, Clay, Morton, Gail , Why Johnny Doesn't Flap: NT is OK! [Morton, Clay, Morton, Gail, Merry, Alex] on Amazon.com. *FREE* shipping on qualifying offers. Why Johnny Doesn't Flap:  If you were to say Alicia Keys doesn’t wear makeup and just relies on her really great skincare routine, you’d be right.And if you were to argue that she actually does wear makeup, and you've

import requests

from bs4 import BeautifulSoup

base_url = "https://festivalfans.nl/event/dominator-festival"
url = requests.get(base_url)
soup = BeautifulSoup(url.content , "html.parser")

def get_date_info():

    for link in soup.find_all("div", {"class": "event-single-data"}):
        day = link.find('div', {"class":"event-single-day"}).text.replace(" ", '')
        month = link.find('div', {"class": "event-single-month"}).text.replace('/', "").replace(' ', '')
        year = link.find('div', {"class": "event-single-year"}).text.replace(" ", '')
        print(day, month, year)

get_date_info()

here is an easier code no need of re

Biden Fumbles Interview: Why Doesn't Trump Act Like A President , Biden Fumbles Interview: Why Doesn't Trump Act Like A President? "That's A Stupid Way To Say It, Sorry". More Videos. Next Up. Biden At  Cats may purr while they demonstrate aggression — you may have seen your cat purr even as his tail puffs up to about three times its normal size. Cats also purr when they are sick, injured or scared. It’s been suggested that the purr has healing powers, and there may well be some truth to that. Not Every Cat Purrs. So why doesn’t your cat

A president should want all Americans to vote. Why doesn't Trump , Why doesn't Trump? A precinct deputy in St. Petersburg, Fla., wears gloves to assist voters dropping off ballots during Florida's primary election  Here's Why Donald Trump Doesn't Want Anyone To Know His Grades Or SAT Scores Christopher Rim Senior Contributor Opinions expressed by Forbes Contributors are their own.

Jason Fried: Why work doesn't happen at work, Jason Fried has a radical theory of working: that the office isn't a good place to do it. He calls out the two main offenders (call them the M&Ms) and offers three  Why doesn’t the U.S. use the metric system? Phil Lewis/shutterstock As of today, the entire world has adopted the metric system, with the exception of the United States, Myanmar, and Liberia

Why Doesn't My Child Want To Go Outside?, Why Doesn't My Child Want To Go Outside? It's important we all stay home during the UK lockdown, but some parents are finding their children  In 1990, the Italian government enlisted top engineers to stabilize Pisa’s famous Leaning Tower. There’d been many attempts during its 800 year history, but computer models revealed the urgency of their situation. The tower would topple if it reached an angle of 5.44 degrees— and it was currently leaning at 5.5. What gives the tower its infamous tilt? Alex Gendler explores the monument's

Comments
  • You're not returning the string at the end of remove_char function. With return string at the end it should work.
  • Damn, case closed!