Web scraping, problem. Noob here | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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

20th Nov 2020, 4:50 AM
kluski śląskie
kluski śląskie - avatar
4 Answers
+ 6
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
20th Nov 2020, 6:53 AM
Arsenic
Arsenic - avatar
+ 4
If possible, can you share the entire code here ? - you can put it on code playground and then attach it with your question.
20th Nov 2020, 5:03 AM
Arsenic
Arsenic - avatar
+ 1
Arsenic attached
20th Nov 2020, 5:28 AM
kluski śląskie
kluski śląskie - avatar
0
Arsenic YES! Totally what I was looking for. Thank you so much :)
20th Nov 2020, 11:36 AM
kluski śląskie
kluski śląskie - avatar