I need help with my Twitter bot that will auto tweet every hour (i have sorted out all the api and stuff so its all good). But i cannot seem to be able to run BeautifulSoup the way i intend to and i get the same error everytime. found = soup.find (almost at the end of the code) won’t work (because i am new to bs4).
What am i doing wrong?
# model scraping for spacepics
import requests
from bs4 import BeautifulSoup as bs
import os
import tweepy as tp
import time
#Posting to twitter
consumer_key = ''
consumer_secret = ''
access_token = ''
access_secret = ''
# login to twitter account api
auth = tp.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tp.API(auth)
while True:
#Get Bitcoin Price
url = 'https://coinmarketcap.com/currencies/bitcoin/'
# download page for parsing
page = requests.get(url)
soup = bs(page.text, 'html.parser')
found = soup.find('div', {'class' : 'col-xs-6 col-sm-8 col-md-4 text-left'}). find("span", {"class" : "text-large2"})
#Update Twitter
status = time.strftime("%Y-%m-%d %H:%M:%S ") + "Bitcoin price currently at $" + found.text + " coinmarketcap.com"
api.update_status(status)
time.sleep(3600)
3
Answers
If the error is at this line:
try to not use spaces after calling a method (the last find):
I think if you use the following code it would return the correct price:
Coinmarketcap has it’s own API accesses which you can use for free so you don’t have to parse the outputs. https://coinmarketcap.com/api/