반응형
import requests
import urllib3
import re
# 주식의 종목명을 추출하는 함수
def get_hname(shcode):
urllib3.disable_warnings()
URL = "https://finance.naver.com/item/main.nhn?code=" + shcode
response_data = requests.get(URL, verify=False, headers={
'referer': "https://navercomp.wisereport.co.kr/v2/company/c1030001.aspx?cmp_cd=005930&cn="})
html = response_data.text
regex = re.compile("종목명 .*")
mo = regex.search(html)
hname = mo.group()[4:].replace('</dd>', '')
return hname
print(get_hname('005930'))
반응형
'Language > python' 카테고리의 다른 글
| 파이썬으로 주식 포트폴리오구성 (1) | 2021.06.03 |
|---|---|
| [ Python library ] 우선주를 보통주로 변환 함수 (1) | 2021.06.03 |
| [ Python library ] 주식 현재가 추출 함수(naver증권 webcrolling) (0) | 2021.06.03 |
| [ Python library ] 네이버 encparam 추출 함수 (0) | 2021.06.03 |
| 로그인 및 현재가조회(xingapi이용) (0) | 2021.05.20 |