Web Scraping-Skript mit BeautifulSoup4 und Python 3.0 Ich möchte das $ -Zeichen (im Ergebnis) aus Preis Preis, machen Sie es vom Typ float und führen Sie einige numerische Operation auf es. Aber es ist im Text.Web Scraping und Python Datentypen
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)
threading.Timer(5.0, bitcoin_scheduler).start()
bitcoin_scheduler()
Ergebnis:
Wed Nov 15 16:37:20 2017 (BTC) $6962.29
Wed Nov 15 16:37:25 2017 (BTC) $6962.29
Wed Nov 15 16:37:31 2017 (BTC) $6962.29
Wed Nov 15 16:37:36 2017 (BTC) $6962.29
Dies ist eine Geschichte, keine Frage. Was hast du versucht und wie ist es gescheitert? – timgeb
Könnte helfen https://docs.python.org/3.0/library/stdtypes.html#str.replace –