I\'m extracting content from this url.
import requests
from bs4 import BeautifulSoup
url = \'https://www.collinsdictionary.com/dictionary/french-english/aimer\'
try 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()
entry_name = soup.h2.text
content1 = ''.join(map(str, soup.select_one('.cB.cB-def.dictionary.biling').contents))
When you select classes and it is blank-spaces
in it you replace the space with .
.
cB
, cB-def
, dictionary
and biling
is four different classes. And if you let the spaces be there the script looking for a tag with class cB-def
inside of a tag with class cB
and so on....