[root@xmonmng1 /tmp]# python /root/job/script/stock.py 셀트리온
셀트리온제약 62,200 -0.32%
셀트리온헬스케어 73,300 -1.35%
셀트리온 215,000 +0.47%
.
======================================
#!/usr/bin/env python
#-*- coding: euc-kr -*-
import sys
import urllib as ul
reload(sys) # Reload does the trick!
sys.setdefaultencoding('UTF8')
C_RED = "\033[31m"
C_BLUE = "\033[34m"
C_END = "\033[0m"
try:
import requests
from bs4 import BeautifulSoup
except ImportError:
print("Please install requests, BeautifulSoup.")
def usage():
print "Usage: %s code" % sys.argv[0]
exit(255)
if len(sys.argv) == 1:
usage()
#code = ul.quote_plus((sys.argv[1]).decode('utf-8').encode('euc-kr'))
code = sys.argv[1]
print(code)
url = "https://finance.naver.com/search/searchList.nhn?query=" + code
s = requests.get(url)
plain_text = s.text
#print(plain_text)
soup = BeautifulSoup(plain_text, "lxml")
#print(soup)
#ranks = soup.find("tr",{"td":"tit"})
ranks = soup.find_all("tr")
#print(ranks)
for i in range(1, len(ranks)):
#name = ranks[i].find_all("td",{"class":"tit"})
name = ranks[i].find_all("a")
pay = ranks[i].find_all("td")
what = ranks[i].find_all("td",{"class":"num3"})
# print(name[0].text.encode('utf-8')),;print('\t'),;print(pay[1].text.encode('euc-kr')),;print('\t'),;print(what[0].text.encode('euc-kr'))
if what[0].text.startswith('+'):
color = C_RED
else:
color = C_BLUE
print(name[0].text),;print('\t'),;print(pay[1].text),;print('\t'),;print(color + what[0].text + C_END)
# print(pay[1].text)
#print(ranks)
#if ranks == None:
# print "Unknown code(%s)" % code
# exit(255)
#print ranks.get_text()
#exit(0)
xen 호스트 아이피 정보 가져오기 (0) | 2018.06.15 |
---|---|
코딩 연습 (0) | 2018.04.18 |