코드:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
from tkinter import*
import requests
from bs4 import BeautifulSoup
def get_bs_obj(company_code):
url = "https://finance.naver.com/item/main.nhn?code=" + company_code
result = requests.get(url)
bs_obj = BeautifulSoup(result.content, "html.parser")
return bs_obj
#bs_obj를 받아서 price를 return
def get_price(company_code):
bs_obj = get_bs_obj(company_code)
no_today = bs_obj.find("p", {"class": "no_today"})
blind_now = no_today.find("span", {"class": "blind"})
return blind_now.text
#company_codes = ["005930","000660"]
def get_Price_from_ent():
f = ent.get();
lbl_2.configure(text = str(get_price(f)))
return
root = Tk()
root.title("Stock Program ")
root.geometry("540x280")
lbl_1 = Label(root, text = "Company Number")
ent = Entry(root)
lbl_2 = Label(root, text = "0")
btn = Button(root, text = "Search", command = get_Price_from_ent)
lbl_1.place(x = 20, y = 30)
ent.place(x = 150, y = 30)
btn.place(x = 150, y = 70)
lbl_2.place(x = 150, y = 120)
root.mainloop()
|
cs |
실행결과:
설명:
005930은 삼성전자의 번호이다.
위 코드는 Python,crawling, bs4,인기검색어 가져오기
Python,crawling, bs4,인기검색어 가져오기
코드 : 1 2 3 4 5 6 7 8 9 import bs4 import urllib.request url = "http://naver.com" html = urllib.request.urlopen(url) bsobj = bs4.BeautifulSoup(html, "html.parser") realtime_hotkeyword = bsobj.find_..
coding-0830.tistory.com
Python, Tkinter, 화씨에서 섭씨로 바꾸기
코드: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 from tkinter import* #function which actions when the button is pushed def convert(): f = float(ent.get()) tmp = float(5 *..
coding-0830.tistory.com
두 개의 내용을 합친 것이다.
'Python > Tkinter' 카테고리의 다른 글
Python, Tkinter, Crawling, Openpyxl, pandas, xlrd, bs4, urllib.request, requests, 상승주 가져와서 모의로 사고 팔기 (0) | 2019.10.06 |
---|---|
Python, Tkinter, 화씨에서 섭씨로 바꾸기 (0) | 2019.10.04 |