简体   繁体   English

Web数据上的Python移动平均

[英]Python moving average on web data

Relatively new to python so apologies if I ask a stupid question. 如果我问一个愚蠢的问题,相对较新的python表示歉意。

I just want to check if this is possible and if it is how complex. 我只想检查这是否可行以及它是否复杂。

I would like to calculate the moving average from share data on this web page 我想根据此网页上的共享数据计算移动平均线

https://uk.finance.yahoo.com/q/hp?a=&b=&c=&d=11&e=16&f=2015&g=d&s=LLOY.L%2C+&ql=1 https://uk.finance.yahoo.com/q/hp?a=&b=&c=&d=11&e=16&f=2015&g=d&s=LLOY.L%2C+&ql=1

You can use this sample code. 您可以使用此示例代码。

import urllib
from BeautifulSoup import *

url = raw_input('Enter - ')
html = urllib.urlopen(url).read()

soup = BeautifulSoup(html)
# Retrieve all of the anchor tags
tags = soup('span')
for tag in tags:
   # Look at the parts of a tag
   #calculate whatever you wanto

Try it: 试试吧:

from urllib import request
from bs4 import BeautifulSoup

url = "https://uk.finance.yahoo.com/q/hp?a=&b=&c=&d=11&e=16&f=2015&g=d&s=LLOY.L%2C+&ql=1"
html_contents = request.urlopen(url).read()

page = BeautifulSoup(html_contents, "html.parser")
el_list = page.find_all("span", {"id": "yfs_p43_lloy.l"})
print(el_list[0])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM