简体   繁体   中英

Infinite loop Python Threading

Im trying to set up the infinite loop to get the latest currency every 5 seconds and to show up that currency in my terminal but for some reason I see the current currency just once and that's it.

Could you guys please tell me how to improve my code to see the current currency every 5 seconds?

PS The programm keeps working without any errors: Here's what I see:

/Users/iprahka/PycharmProjects/Test2/main.py:6: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(executable_path='/Applications/Python 3.10/chromedriver')
[<div class="subPrice">₽1,511,937.64</div>]```


And here's my code:

from threading import Thread
from bs4 import BeautifulSoup
import time
from selenium import webdriver

driver = webdriver.Chrome(executable_path='/Applications/Python 3.10/chromedriver')
def runA():
    while True:

        url = 'https://www.binance.com/trade/BTC_USDT?theme=dark&type=spot'
        driver.get(url)
        time.sleep(5)
        response = driver.page_source
        soup = BeautifulSoup(response, 'html.parser')
        convert = soup.findAll('div', {'class': 'subPrice'})
        print(convert)
        return convert[0].text

if __name__ == "__main__":
    t1 = Thread(target = runA)
    t1.daemon
    t1.start()
    while True:
        pass

Thanks a lot

Perhaps you should not use return it stops the function

More info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM