-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_dollar_price.py
39 lines (34 loc) · 1.4 KB
/
get_dollar_price.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import requests
from bs4 import BeautifulSoup
# Function to get the dollar and gold prices in Iranian Toman for any given time
def get_prices():
# Placeholder website URL
url = "https://irarz.com/"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}
# Make a request to the website
response = requests.get(url , headers= headers)
# Check if the request was successful
if response.status_code == 200:
# Parse the HTML content of the page
soup = BeautifulSoup(response.text, 'html.parser')
# Assuming the prices are in elements with specific IDs or classes
# You'll need to inspect the website to find the correct selectors
dollar_price_element = soup.find(id='usdmax')
if dollar_price_element:
# Extract the prices
dollar_price = dollar_price_element.text
return dollar_price # all prices are in "Rial"
else:
print("Failed to find price elements.")
return None
else:
print("Failed to fetch page. Status code:", response.status_code)
return None
# Get the dollar and gold prices for the current time
dollar_price = get_prices()
if dollar_price:
print("Dollar price in Rial:", dollar_price)
else:
print("Failed to fetch prices.")