To get content of the page, you can use .get_text()
method, no need to replace sections of soup with empty string:
import requests
from bs4 import BeautifulSoup
url = 'https://www.collinsdictionary.com/dictionary/french-english/aimer'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0'}
soup = BeautifulSoup(requests.get(url, headers=headers).content, 'html.parser')
print(soup.h2.text)
print(soup.select_one('.hom').get_text(strip=True, separator=' '))
Prints:
aimer
Full verb table transitive verb 1. ( d’amour ) to love Elle aime ses enfants. She loves her children. 2. ( d’amitié, par affection ) to like bien aimer qn to like sb J’aime bien Paul, on peut vraiment compter sur lui. I really like Paul, he’s so reliable. Je n’aime pas beaucoup Marie. I don’t like Marie very much. 3. ( par goût ) [ aliment, divertissement, auteur ] to like Tu aimes le chocolat ? Do you like chocolate? bien aimer qch to like sth J’aime bien jouer au tennis. I like playing tennis. aimer faire qch to like doing sth J’aime assez aller au cinéma. I quite like going to the cinema. 4. ( préférence ) aimer mieux qn que qn to prefer sb to sb aimer mieux qch que qch to prefer sth to sth J’aime mieux Paul. I prefer Paul. J’aime mieux Paul que Pierre. I prefer Paul to Pierre. Il aime mieux faire la cuisine qu’aller au restaurant. He’d rather cook than go to a restaurant. j’aime mieux vous dire que , j’aime autant vous dire que I may as well tell you that 5. ( conditionnel : souhait ) j’aimerais ... I would like ... J’aimerais aller en Écosse. I’d like to go to Scotland. Aimeriez-vous que je vous accompagne ? Would you like me to come with you? j’aimerais bien ... I would like ... J’aimerais bien m’en aller. I’d like to go. j’aimerais mieux faire ... I’d rather do ... J’aimerais mieux ne pas y aller. I’d rather not go. J’aimerais mieux y aller maintenant. I’d rather go now. J’aimerais autant y aller maintenant. I’d rather go now.
EDIT: To get HTML markup, you can do this:
import requests
from bs4 import BeautifulSoup
url = 'https://www.collinsdictionary.com/dictionary/french-english/aimer'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0'}
soup = BeautifulSoup(requests.get(url, headers=headers).content, 'html.parser')
for script in soup.select('script, .hcdcrt, #ad_contentslot_1, #ad_contentslot_2'):
script.extract()
print(soup.h2.text)
print(''.join(map(str, soup.select_one('.hom').contents)))
Prints:
aimer
<span class="gramGrp"><span class="xr"> <a class="link-right verbtable" href="https://www.collinsdictionary.com/dictionary/french-english/conjugation/aimer">Full verb table</a>
</span><span class="hi rend-sc pos">transitive verb</span></span><div class="sense"><span class="sensenum bluebold">1. </span> <span class="lbl type-misc"><span class="punctuation">(</span>d’amour<span class="punctuation">)</span></span> <span class="cit type-translation quote">to love</span><div class="cit type-example"><span class="quote">Elle aime ses enfants.</span> <span class="cit type-translation quote">She loves her children.</span></div></div><div class="sense"><span class="sensenum bluebold">2. </span> <span class="lbl type-misc"><span class="punctuation">(</span>d’amitié, par affection<span class="punctuation">)</span></span> <span class="cit type-translation quote">to like</span><div class="re type-phr"><span class="form type-phr orth">bien aimer qn</span> <span class="cit type-translation quote">to like sb</span><div class="cit type-example"><span class="quote">J’aime bien Paul, on peut vraiment compter sur lui.</span> <span class="cit type-translation quote">I really like Paul, he’s so reliable.</span></div><div class="cit type-example"><span class="quote">Je n’aime pas beaucoup Marie.</span> <span class="cit type-translation quote">I don’t like Marie very much.</span></div></div> </div><div class="sense"><span class="sensenum bluebold">3. </span> <span class="lbl type-misc"><span class="punctuation">(</span>par goût<span class="gramGrp colloc"><span class="punctuation">) </span><span class="punctuation">[</span>aliment, divertissement, auteur<span class="punctuation">]</span></span></span> <span class="cit type-translation quote">to like</span><div class="cit type-example"><span class="quote">Tu aimes le chocolat ?</span> <span class="cit type-translation quote">Do you like chocolate?</span></div><div class="re type-phr"><span class="form type-phr orth">bien aimer qch</span> <span class="cit type-translation quote">to like sth</span><div class="cit type-example"><span class="quote">J’aime bien jouer au tennis.</span> <span class="cit type-translation quote">I like playing tennis.</span></div></div><div class="re type-phr"><span class="form type-phr orth">aimer faire qch</span> <span class="cit type-translation quote">to like doing sth</span><div class="cit type-example"><span class="quote">J’aime assez aller au cinéma.</span> <span class="cit type-translation quote">I quite like going to the cinema.</span></div></div> <div class="mpuslot_b-container">
</div> </div><div class="sense"><span class="sensenum bluebold">4. </span> <span class="lbl type-misc"><span class="punctuation">(</span>préférence<span class="punctuation">)</span></span><div class="re type-phr"><span class="form type-phr orth">aimer mieux qn que qn</span> <span class="cit type-translation quote">to prefer sb to sb</span></div><div class="re type-phr"><span class="form type-phr orth">aimer mieux qch que qch</span> <span class="cit type-translation quote">to prefer sth to sth</span><div class="cit type-example"><span class="quote">J’aime mieux Paul.</span> <span class="cit type-translation quote">I prefer Paul.</span></div><div class="cit type-example"><span class="quote">J’aime mieux Paul que Pierre.</span> <span class="cit type-translation quote">I prefer Paul to Pierre.</span></div><div class="cit type-example"><span class="quote">Il aime mieux faire la cuisine qu’aller au restaurant.</span> <span class="cit type-translation quote">He’d rather cook than go to a restaurant.</span></div></div><div class="re type-phr"><span class="form type-phr orth">j’aime mieux vous dire que</span><span class="form type-phr"><span class="punctuation">, </span><span class="orth">j’aime autant vous dire que</span></span> <span class="cit type-translation quote">I may as well tell you that</span></div> </div><div class="sense"><span class="sensenum bluebold">5. </span> <span class="lbl type-misc"><span class="punctuation">(</span>conditionnel : souhait<span class="punctuation">)</span></span><div class="re type-phr"><span class="form type-phr orth">j’aimerais ...</span> <span class="cit type-translation quote">I would like ...</span><div class="cit type-example"><span class="quote">J’aimerais aller en Écosse.</span> <span class="cit type-translation quote">I’d like to go to Scotland.</span></div><div class="cit type-example"><span class="quote">Aimeriez-vous que je vous accompagne ?</span> <span class="cit type-translation quote">Would you like me to come with you?</span></div></div><div class="re type-phr"><span class="form type-phr orth">j’aimerais bien ...</span> <span class="cit type-translation quote">I would like ...</span><div class="cit type-example"><span class="quote">J’aimerais bien m’en aller.</span> <span class="cit type-translation quote">I’d like to go.</span></div></div><div class="re type-phr"><span class="form type-phr orth">j’aimerais mieux faire ...</span> <span class="cit type-translation quote">I’d rather do ...</span><div class="cit type-example"><span class="quote">J’aimerais mieux ne pas y aller.</span> <span class="cit type-translation quote">I’d rather not go.</span></div><div class="cit type-example"><span class="quote">J’aimerais mieux y aller maintenant.</span> <span class="cit type-translation quote">I’d rather go now.</span></div><div class="cit type-example"><span class="quote">J’aimerais autant y aller maintenant.</span> <span class="cit type-translation quote">I’d rather go now.</span></div></div> <div class="mpuslot_b-container">
</div> </div>