-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathinfo_from_bitkurs.ru.py
44 lines (29 loc) · 1.32 KB
/
info_from_bitkurs.ru.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
40
41
42
43
44
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "ipetrash"
import re
import grab
URL = "http://bitkurs.ru/"
# Copy page yandex
# URL = 'http://hghltd.yandex.net/yandbtm?fmode=inject&url=http%3A%2F%2Fbitkurs.ru%2F&tld=ru&lang=ru&la=1453455360&tm=1454924280&text=bitkurs.ru&l10n=ru&mime=html&sign=2105e628b413520a0e087ae4ac0db180&keyno=0'
g = grab.Grab()
g.setup(proxy="proxy.compassplus.ru:3128", proxy_type="http")
g.go(URL)
# <div class='currency_block'>
# <span class="btc_c currencies">1 BTC =</span>
# <span class="usd_c currencies">$397.16<img src="/template/images/down.png"></span>
# <span class="rub_c currencies">19 862.57 руб.<img src="/template/images/down.png">
# </span><span class="eur_c currencies">366.51 &euro
usd = g.doc.select('//span[@class="usd_c currencies"]').text()
rub = g.doc.select('//span[@class="rub_c currencies"]').text()
eur = g.doc.select('//span[@class="eur_c currencies"]').text()
def get_amt(text):
# Удаление всех символов, кроме цифр и точки
text = re.sub(r"[^\d.]+", "", text)
# Вытаскивание строки, описывающей число
text = re.search(r"\d+(\.\d*)?", text).group()
return text
usd = get_amt(usd)
rub = get_amt(rub)
eur = get_amt(eur)
print(f"1 BTC:\n {usd} USD\n {rub} RUB\n {eur} EUR")