Search programs, how do I block spaces?

Asked 2 years ago, Updated 2 years ago, 92 views

We are making a program that searches for products on various sites using Beautiful Soup4. The problem is that the search function uses url of each site, which has different search logic for each site and different processing results for each space. Some sites don't print out any results if you don't type anything, while others show the entire product if you don't type anything. And there are sites that show the entire product or not when you enter the space bar. For this reason, in order to show consistent results, we would like to create a conditional statement called 'when you enter nothing or just enter the space bar'. A more accurate expression would be 'when there is nothing in the variable or only a space bar'

search=" #Variable where the space bar is stored (search word)

If search==" or search==": #That's the conditional statement I thought of.
    print("None entered".")

If you write and run as above, print() will be executed, but if the user enters more than one space bar, it does not meet the conditions. Is it possible to prevent multiple space bars from being entered?

space none

2022-09-21 16:17

1 Answers

Can't we just trim and delete the space?


2022-09-21 16:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.