5
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonで日経平均株価を取得してみた・

Posted at

今回は日経平均株価を取得してみました。今回もurllib3とBeautifulsoup4を使用しています。

まず日経平均株価のURLにアクセスしないといけません。
"http://www.nikkei.com/markets/kabu/

日経平均株価を取得するためには、データ上でHTMLを取得する必要があります。日経平均株価を右クリックして検証して、span要素のところに日経平均株価があります。

qiita.rb
import urllib.request
from bs4 import BeautifulSoup

url =  "http://www.nikkei.com/markets/kabu/"

html = urllib.request.urlopen(url)

soup = BeautifulSoup(html,"html.parser")

span = soup.find(class_="mkc-stock_prices")

print(span.string)
5
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?