PythonでWebページの取得 (03)

この記事の目標

米国株の目標株価の最大値,平均,最小値を取得する
(平均値のみを得るこの記事を拡張します)

プログラム

03.py

from lxml import html
import sys

xpaths = [
       "/html/body/div[5]/section/div[8]/div[2]/div[1]/p[1]/text()[2]",
       "/html/body/div[5]/section/div[8]/div[2]/div[1]/p[2]/text()[2]",
       "/html/body/div[5]/section/div[8]/div[2]/div[1]/p[3]/text()[2]"
]

ht = html.fromstring(sys.stdin.read())

for an_xpath in xpaths:
       for token in ht.xpath(an_xpath):
               print(token, end=" ")
print()

実行方法

wget https://www.investing.com/equities/apple-computer-inc-consensus-estimates -O - | python3 03.py

実行結果

 215.00  190.77  160.00


この記事が気に入ったらサポートをしてみませんか?