How find and count matches for a word - Python - Scrapping

1199 views python
-2

I need found the matches of a WORD, for example:

Found all words "Learn" in the web https://www.georgetown.edu/ (Result: 4 words) (you can see it press CTRL + F and search)

I have my Python code, but my count match is 3! If I look for another word, the result is one less or one more

import requests
from bs4 import BeautifulSoup
import re

page = requests.get("https://www.georgetown.edu/")
soup = BeautifulSoup(page.text, 'html.parser')
solo_body = soup.body
limpiar_body = solo_body.text
contar_coincidencias = (limpiar_body.count("learn"))
print(contar_coincidencias)

Actually use Python3, "find_all" not working for me.

answered question

1 Answer

6

you need to count both upper and lower case. replace limpiar_body = solo_body.text with limpiar_body = solo_body.text.lower()

posted this

Have an answer?

JD

Please login first before posting an answer.