我怎么会单独得到这个文本?

How would i get this text alone?

我正在尝试网络抓取 https://www.officialcharts.com/charts/uk-top-40-singles-chart/ 并获取所有标题。 到目前为止,这是我的代码:

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup

my_url = 'https://www.officialcharts.com/charts/uk-top-40-singles-chart/'

#opening coonnection, grabbing page
uClient = uReq (my_url)
page_html = uClient.read()
uClient.close()

#html parsing
page_soup = soup(page_html, "html.parser")
#print (page_soup.p)

#grabs each section
containers = page_soup.findAll('div' ,{"class":"title-artist"})

contain = containers[0]
container = containers[0]

但我目前处于需要自己获得称号的阶段。到目前为止,我已经尝试过:container.div.a 将 html 缩小为:

<a href="/search/singles/savage-love-(laxed---siren-beat)/">SAVAGE LOVE (LAXED - SIREN BEAT)</a>

我需要自己获得标题“SAVAGE LOVE(LAXED - SIREN BEAT)”,但我不确定如何做到这一点。 我正在使用 Spyder 和 Python 3.7 谢谢! :)

.text 属性应该可以满足您的需求。

解决方案:

>>> container.find('a').text
'SAVAGE LOVE (LAXED - SIREN BEAT)'