href = ('http://www.funda.nl' + ad.find_all('a')[2]['href']) area = get_single_item_data_3(href) if not area: area = 'None' print(title + "," + address + "," + price + "," + size + "," + room + "," + area + "," + href)a function always returns something, whether it is your value or None. Just check the value and reassign it to something as a string if it is none.
You should use format method too. It is much more readable, and easier to maintain. As well as it is now the standard. Concatenation looks horrible.
print('{},{},{},{},{},{},{}'.format(title, address, price, size, room, area, href))If you want to change the output to not even show area value when its none, then do somethign like
area = get_single_item_data_3(href) if area: print('{},{},{},{},{},{},{}'.format(title, address, price, size, room, area, href)) else: print('{},{},{},{},{},{}'.format(title, address, price, size, room, href))
Recommended Tutorials: