eg0rmaffin

scraping_binance.py

Dec 26th, 2020
1,257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import requests
  2. from requests_html import HTMLSession
  3. from bs4 import BeautifulSoup
  4. import time
  5. from datetime import datetime
  6.  
  7.  
  8.  
  9.  
  10.  
  11. while True:
  12.     session = HTMLSession()
  13.     r = session.get('https://www.binance.com/ru/trade/ETH_BTC')
  14.     r.html.render(sleep = 1, keep_page=True, scrolldown=1, timeout=100)
  15.     soup = BeautifulSoup(r.html.html, "lxml")
  16.  
  17.     price = soup.find("div", class_ = lambda value: value and value.startswith("showPrice"))
  18.  
  19.     # with open('index.html', 'w', encoding="utf-8") as f:
  20.     #     f.write(soup.prettify())
  21.     #     f.close()
  22.  
  23.     now = datetime.now()
  24.     dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
  25.     print(dt_string + " ETH/BTC: " +  price.text)
  26.  
  27.     time.sleep(4)
Advertisement
Add Comment
Please, Sign In to add comment