2021年2月7日星期日

Trying crawling, but the only one works, not the others

import telegram  from telegram.ext import Updater, MessageHandler, Filters  import requests  from bs4 import BeautifulSoup    token=''  chat_id =   bot = telegram.Bot(token)  updater = Updater(token=token)  dispatcher = updater.dispatcher  updater.start_polling()    bot.sendMessage(chat_id=chat_id, text='Welcome!')      def handler(update, context):      text = update.message.text      chat_id = update.message.chat_id        if 'bot' in text:          bot.send_message(chat_id=chat_id, text='Did you call me?')        if text.startswith("hi"):          bot.send_message(chat_id=chat_id, text='Hello')        if text.startswith("eth"):          html = requests.get("https://coinmarketcap.com/currencies/ethereum/")          soup = BeautifulSoup(html.text, 'html.parser')          price = soup.find('td').text          change = soup.find('p',{'class': 'sc-1eb5slv-0 sc-1siv958-1 lfjNAJ'}).text          bot.send_message(chat_id=chat_id, text='CURRENT ETH PRICE' + '\n' + price + '\n' + 'IN USD' + '\n' + 'LAST 24 HOURS' + '\n' + change)        if text.startswith("DFM"):          html = requests.get("https://etherscan.io/token/0x0ccD5DD52Dee42B171a623478e5261C1eaaE092A")          soup = BeautifulSoup(html.text, 'html.parser')          priced = soup.find('div', {'class': 'col-6'}).find_all('span', {'class':'d-block'}).text          pricede = soup.find('span', {'class': 'small text-secondary text-nowrap'}).text          circu = soup.find('button', {'class': 'u-label u-label--sm u-label--value u-label--text-dark u-label--secondary rounded'}).text          bot.send_message(chat_id=chat_id, text='CURRENT DFM token PRICE' + '\n' + priced + '\n' + 'IN USD' + '\n' + pricede + '\n' + 'IN ETH' + '\n' + 'CIRCULATING SUPPLY MARKET CAP' + circu)                echo_handler = MessageHandler(Filters.text, handler)  dispatcher.add_handler(echo_handler)  

The first crawling with eth does work, but the other one, DFM, does not work. I couldn't find out what the problem is. And I tried to crawl eth from https://ethereum.org/en/get-eth/ but I couldn't as well.

##price = soup.find('div', {'class': 'col-6'}).text  ##price = soup.find("div",attrs={"class":"col-6"}).find_all("span", attrs={"class":"d-block"}).text  ##price = soup.select_one('div.col-6 span.d-block').text  

These are other codes I tried in the other way. I do not know what information is needed to understand my situation, I use Python Idle.

https://stackoverflow.com/questions/66094586/trying-crawling-but-the-only-one-works-not-the-others February 08, 2021 at 08:39AM

没有评论:

发表评论