擅长:python、mysql、java
<p>使用replace()方法,或者使用strip()方法</p>
<pre><code>import requests
from bs4 import BeautifulSoup
def bitcoin_scheduler():
url = "https://coinmarketcap.com/currencies/bitcoin/"
r = requests.get(url)
offline_data = r.content
soup = BeautifulSoup(offline_data, 'html.parser')
name_box = soup.find('small', attrs={'class': 'bold hidden-xs'})
name = name_box.text.strip()
price_box = soup.find('span', attrs={'class': 'text-large'})
price = price_box.text.strip()
print(time.ctime(), name, price.replace('$',''))
threading.Timer(5.0, bitcoin_scheduler).start()
bitcoin_scheduler()
</code></pre>