I only need the value "Central Bank Digital Currency (CBDC) Tracker" to show up. However im getting a bunch of other attributes when i run my code. Im using the cbdctracker.org website.
import requests
from bs4 import BeautifulSoup
URL = "https://cbdctracker.org/"
response = requests.get(URL)
website_html = response.text
soup= BeautifulSoup(website_html, "html.parser")
#print(soup)
res = soup.find_all('meta')
res[6]
#print(res)
soup.attrs={"content": "twitter:title"}
print(res[6])
CodePudding user response:
Try:
import requests
from bs4 import BeautifulSoup
URL = "https://cbdctracker.org/"
response = requests.get(URL)
website_html = response.text
soup = BeautifulSoup(website_html, "html.parser")
print(soup.select_one('meta[name="twitter:title"]')["content"])
Prints:
Central Bank Digital Currency (CBDC) Tracker