Форум сайта python.su
Блок просто считывает цифровое значение курса валюты постоянно изменяющееся.
Ребята помогите пожалуйста адаптировать к python3, смог сваять на python 2,7 на нем работает.
Или подскажите пожалуйста путь по кторому нужно пойти чтобы это сделать самому. Заранее благодарен.
[/ import re import urllib htmlfile=urllib.urlopen("https://es.finance.yahoo.com/q?s=EURRUB=X&ql=1") htmltext = htmlfile.read() regex='<span id="yfs_l10_eurrub=x">(.+?)</span>' pattern= re.compile(regex) yfs=re.findall(pattern,htmltext) print yfs ]
Офлайн
import re from urllib.request import urlopen htmlfile=urlopen("https://es.finance.yahoo.com/q?s=EURRUB=X&ql=1") htmltext = htmlfile.read().decode() regex='<span id="yfs_l10_eurrub=x">(.+?)</span>' pattern=re.compile(regex) yfs=re.findall(pattern,htmltext) print(yfs)
Офлайн
>>> import urllib.request >>> import re >>> >>> htmlfile = urllib.request.urlopen('https://es.finance.yahoo.com/q?s=EURRUB=X&ql=1') >>> htmltext = htmlfile.read().decode('latin1') >>> htmlfile.close() >>> >>> regex = r'<span id="yfs_l10_eurrub=x">(.+?)</span>' >>> pattern = re.compile(regex) >>> >>> yfs = pattern.findall(htmltext)[0] >>> print(yfs) 63,5870 >>>
Отредактировано py.user.next (Янв. 19, 2017 15:17:20)
Офлайн
Благодарю Вас ребята. Что я не так сделал?
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 “/Users/______/Library/Mobile Documents/com~apple~CloudDocs/PYTHON/projects/python2_to_python3/scraper es.Yahoo finanse”
File “/Users/_______/Library/Mobile Documents/com~apple~CloudDocs/PYTHON/projects/python2_to_python3/scraper es.Yahoo finanse”, line 4
htmlfile= urllib.request.urlopen('https://es.finance.yahoo.com/q?s=EURRUB=X&ql=1')
^
IndentationError: unexpected indent
Process finished with exit code 1
Прикреплённый файлы:
Screen Shot 2017-01-19 at 15.07.57.jpg (101,6 KБ)
Офлайн
>IndentationError: unexpected indent
Отсупы расставь.
Офлайн
xkbd
>IndentationError: unexpected indentОтсупы расставь.
Прикреплённый файлы:
Screen Shot 2017-01-19 at 18.46.28.jpg (600,7 KБ)
Офлайн
Так для информации:
Python 3.5.1 (default, Jan 25 2016, 23:14:25) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from yahoo_finance import Currency >>> eur_rub = Currency('EURRUB') >>> print(eur_rub.get_bid()) 63.6140 >>> print(eur_rub.get_ask()) 63.6300 >>> print(eur_rub.get_rate()) 63.6140 >>> print(eur_rub.get_trade_datetime()) 2017-01-19 22:20:00 UTC+0000 >>> eur_rub.refresh() >>> print(eur_rub.get_rate()) 63.5150
Офлайн
WoMax
Так для информации:
Офлайн