我有这样的代码吐出价格作为一个字符串(125.01),但我一定已经改变了一些东西,因为现在它打印整个行与html标签和一切。我怎样才能打印出来的文本,而不使用正则表达式?美丽的汤发现 - 只是文本
import requests
from bs4 import BeautifulSoup
url = 'http://finance.yahoo.com/q?s=aapl&fr=uh3_finance_web&uhb=uhb2'
data = requests.get(url)
soup = BeautifulSoup(data.content)
price = soup.find("span", {'id':'yfs_l84_aapl'})
print(price)
<span id="yfs_l84_aapl">125.01</span>
已解决。我添加了.get_text()方法,它工作。谢谢@halex –