Python EUR and USD rate parser.
Python USD and EUR rate in RUB parser. Parsing is from https://ru.investing.com/currencies/usd-rub/ and /eur-rub/
And how it works?
Firstly, modules (requests, BeautifulSoup and rich):
import requests
from bs4 import BeautifulSoup as Bs
from rich import print
After that comes the most important part of the program.
def parsing(url, name_body, class_body, text, text2):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
quotes = soup.find_all(name_body, class_=class_body)
print(text)
for quote in quotes:
print(quote.text, text2)
Next is the declaration of a 'parsing' function with 5 variables whose values you can specify when calling the function.
Then the html code of the page declared in the 'url' variable is written into the 'response' variable.
Then in the variable 'soup' is written html code, but in a more readable form and the name of the parser.
Next, the class value from the body part is written to the 'quote' variable. The name of the class and body part is declared when the function is called.
Then the text from the 'text' variable, the value of which is written when the function is called, is output.
Then the result of the parsing is displayed.
The function ends.
parsing("https://ru.investing.com/currencies/usd-rub/", "span", "text-2xl", "1 USD", "RUB")
print("")
parsing("https://ru.investing.com/currencies/eur-rub/", "span", "text-2xl", "1 EUR", "RUB")
input()
At the end of the program our function is announced 2 times to output the dollar and euro rates. That's all.
thx for reading :D