Skip to content

Instantly share code, notes, and snippets.

@mr-yoo
Created December 2, 2017 10:50
Show Gist options
  • Save mr-yoo/a40961a7f62d7e27ce0dd9579abd2fa3 to your computer and use it in GitHub Desktop.
Save mr-yoo/a40961a7f62d7e27ce0dd9579abd2fa3 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
def get_value_by_selector(ticker, selector) :
# Get HTML codes
url = "http://finance.naver.com/item/main.nhn?code=" + ticker
response = requests.get(url).text
# Get the first element of press releases
soup = BeautifulSoup(response, "html5lib")
return soup.select(selector)[0].text
# 삼성전자, 신라젠
ticker_list = ["005930", "215600"]
for ticker in ticker_list:
selector = "#tab_con1 > div:nth-of-type(2) > table > tbody > tr:nth-of-type(1) > td > em"
value = get_value_by_selector(ticker, selector)
print ("외국인한도주식수(A) :", value)
selector = "#tab_con1 > div:nth-of-type(2) > table > tbody > tr:nth-of-type(2) > td > em"
value = get_value_by_selector(ticker, selector)
print ("외국인보유주식수(B) :", value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment