1

Is there any way for printing live data which is being scraped from websites in a single location. Consider the below example for understanding my question.

import requests
import time
print("Selling \t \tbuying")
for i in range(100):
    time.sleep(5)
    r = requests.get("https://api.binance.com/api/v/depth",params=dict(symbol="DOTUSDT"))
    a = r.json()
    b=a['asks'][0][0]
    c=a['bids'][0][0]
    print(b,"\t \t",c)

This program will print output for every 5 seconds new lines will print like this below

Selling                 buying
18.58900000              18.58800000
18.59100000              18.58800000
18.59500000              18.59400000
18.59300000              18.59200000
18.60000000              18.59900000
18.61500000              18.61400000
18.61900000              18.61700000

What i need is , it should not print new values in new lines. It should update with new values in same first line.

KrisH Jodu
  • 104
  • 9
  • Does this answer your question? [How to print without a newline or space](https://stackoverflow.com/questions/493386/how-to-print-without-a-newline-or-space) – blurfus Aug 06 '21 at 03:07
  • and to reset the cursor (caret) position: https://stackoverflow.com/questions/7715594/how-to-reset-cursor-to-the-beginning-of-the-same-line-in-python – blurfus Aug 06 '21 at 03:10
  • No, i am not meant to print besides in a same line, what i need is, it sholud replace that previous value with new value in same position like how live data changes in stocks – KrisH Jodu Aug 06 '21 at 05:30
  • 1
    Well, the first link print on the same line (w/o moving to the next line) - I believe the second shows how to reset the cursor to the beginning of the line to print on it again (effectively, overwriting what was on it previously) – blurfus Aug 06 '21 at 05:50
  • Yes exactly! That is what I want – KrisH Jodu Aug 06 '21 at 15:30

0 Answers0