Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import requests
- from bs4 import BeautifulSoup
- def get_currencies(url, id, currencies, semaphore):
- response = requests.get(url)
- if response.status_code == 200:
- semaphore.acquire()
- try:
- secret_code()
- soup = BeautifulSoup(response.text, 'html.parser')
- currency = str(soup.find_all('valute')[id])
- if currency not in currencies:
- currencies.append(currency)
- finally:
- semaphore.release()
- if __name__ == '__main__':
- currencies = []
- id = int(input())
- semaphore = threading.Semaphore(4)
- threads = []
- for url in urls:
- thread = threading.Thread(target=get_currencies, args=(url, id, currencies, semaphore))
- threads.append(thread)
- thread.start()
- for thread in thread:
- thread.join()
- currencies_string = ''.join(currencies)
- print(currencies_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement