본문 바로가기

Language/python

[ Python library ] 네이버 encparam 추출 함수

반응형

import requests
import re
import urllib3

# 네이버 이용시 필요한 encparam 파라미터 값을 추출하는 함수
def get_encparam():
    urllib3.disable_warnings()
    encparam=""
    URL = "https://navercomp.wisereport.co.kr/v2/company/c1010001.aspx?cmp_cd=005930"
    response_data = requests.get(URL, verify=False, headers={'referer': "https://finance.naver.com/item/coinfo.nhn?code=005930"})
    html = response_data.text
    regex = re.compile("encparam.*")
    mo = regex.search(html)
    if mo != None:
        encparam = mo.group()[10:].replace('\'', '')
    return encparam

print(get_encparam())

반응형