BeautifulSoup 剥离空白

我正在研究一个网站上的基本星座分析器。下面是我的代码:


import requests

from bs4 import BeautifulSoup as bs


url = "https://www.astrospeak.com/horoscope/capricorn"


response = requests.request("GET", url)


soup = bs(response.text, 'html.parser')


locater = soup.select("#sunsignPredictionDiv > div.fullDIV > div.lineHght18 > div")


quote = locater[0].previousSibling

这给我留下了以下内容<class 'bs4.element.NavigableString'>:


"\n                      You are working towards yet another dream and as you pursue this vision there's no doubt in your mind that it will come to fruition. It's written in the stars! \n                      "

我正在努力如何stripped_strings在 bs4.element.NavigableString 上使用 BeautifulSoup生成器。我想最终得到的只是字符串You are working towards yet another dream and as you pursue this vision there's no doubt in your mind that it will come to fruition. It's written in the stars!


慕雪6442864
浏览 196回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python