I am a beginner in python. I am working on a webscraping project. In the project, i want to look up the meaning and POS of some words from cambridge dictionary and export them into excel.
And this is my code:
pip install bs4
pip install requests
from bs4 import BeautifulSoup
import requests
headers = {"User-Agent" : "xxxxxxx"}
r=requests.get('https://dictionary.cambridge.org/dictionary/english/happy', headers=headers)
soup = BeautifulSoup(r.text,'html.parser')
POS = soup.find_all("span", class_="pos dpos")
print(POS)
result:
[<span class="pos dpos" title="A word that describes a noun or pronoun''.>adjective</span>, <span class="pos dpos" title="A word that describes a noun or pronoun.''>adjective</span>]
For the result, I only want to get the word 'adjective'. But I don't know how to do that, is there anyone can help me? Many Thanks.