LoginSignup
2
2

More than 3 years have passed since last update.

やよい軒メニューからPFCバランスをスクレイピング

Posted at

概要

減量中に外食だとカロリー計算に困るので
やよい軒のメニューからカロリー、PFCバランスを取得しておく。

利用技術

  • python3
  • BeautifulSoup

やってみた

コードを書いて

# coding: UTF-8

import urllib.request
from bs4 import BeautifulSoup
import re


# やよい軒 サバの塩焼定食
url = "https://www.yayoiken.com/menu_list/view/467"

# URLにアクセスして html取得
html = urllib.request.urlopen(url)

# htmlをBeautifulSoupでパース
soup = BeautifulSoup(html, "html.parser")

# 栄養素が入っているボックスを取得
eiyo_box = soup.find(class_='eiyo_box')

# カロリー, P, F, Cの数値を取得
eiyoso = eiyo_box.find_all("td")

# 変数化
kcal = eiyoso[0].string
p = eiyoso[1].string
f = eiyoso[2].string
c = eiyoso[3].string

print("サバの塩焼定食\n" + "kcal " + kcal)
print("P " + p)
print("F " + f)
print("C " + c)

こう

$ python3 getYayoi.py
サバの塩焼定食
kcal 768
P 36.3
F 37.6
C 70.5
2
2
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
2
2