Web scraping, problem. Noob here | Sololearn: Learn to code for FREE!


Web scraping, problem. Noob here

So. Im a noob. Pretty much know nothing about programming. Heard that python is easy to learn so I started. I need to get a text from a website and then compare if that text is the same as the text that I typed in. Im doing something like this soup = BeautifulSoup( html, 'html.parser' ) y = soup.find(the things im looking for) x = y.get_text() #print(x) #the output from x is hello a = 'hello' if x == a: print('match') else: print('nope') When I run it the output is nope despite the text being same. I have no clue whats wrong. From what ive read the y.get_text() is not a text value or something like that? I don't know how to convert it or work around it. print('Please help') https://code.sololearn.com/cZtDLhvPTrv7/?ref=app

11/20/2020 4:50:49 AM

kluski śląskie

4 Answers

New Answer


kluski śląskie your code is working fine. The problem is that the string you are getting from the source have newline characters and/or whitespaces in front and behind it. just remove those and then perform the comparison. Here is the fix https://code.sololearn.com/cySbuK0Ih4ad/?ref=app


If possible, can you share the entire code here ? - you can put it on code playground and then attach it with your question.


Arsenic attached


Arsenic YES! Totally what I was looking for. Thank you so much :)