B
B
Babamurat2020-05-17 19:06:08
Python
Babamurat, 2020-05-17 19:06:08

How to get data from the internet?

Hello !
I wrote a program that shows simple moving averages, but I can't get data from the internet.
I need to download the date and price of oil from the Internet. How can I do this please tell me!
Thanks in advance !

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
origami1024, 2020-05-17
@Babamurat

#requests - для скачки странички
import requests
#html из lxml - чтобы парсить DOM дерево
from lxml import html

#забираем страничку с нефтью
raw = requests.get("https://yandex.ru/news/quotes/1006.html")

#строим из нее html дерево
dom = html.fromstring(raw.content)

#забираем xpath-ом ноды с датами и ценами из дерева
dates = dom.xpath('//td[@class="quote__date"]')
prices = dom.xpath('//td[@class="quote__value"]')    

#выводим на экран
for d,p in zip(dates, prices):
    print(d.text_content(), p.text_content())

Sandbox for tests
https://repl.it/@Origami1024/pythonOilParser

D
Dubolom Unicellular, 2020-05-17
@duboloms

selenium.
English tutorials:
https://www.youtube.com/watch?v=7ovFudqFB0Q
Here are the docs:
https://selenium-python.readthedocs.io/

Changed (Important):Although there is a simpler thing:
Beautiful Soup
Here Goshak made a parser for dollar rate:
https://www.youtube.com/watch?v=4L57oY3J378

V
Vladimir Korotenko, 2020-05-17
@firedragon

Try this pycurl.io

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question