본문으로 바로가기

python beautiful soup request

category Language/Python 2018.02.17 13:48

python beautiful soup request


1
2
3
4
5
6
7
8
9
from urllib.request import urlopen
from bs4 import BeautifulSoup
 
html = urlopen("http://companyinfo.stock.naver.com/v1/company/cF3002.aspx?cmp_cd=068270&frq=0&rpt=0&finGubun=MAIN&frqTyp=0&cn=")
bsObj = BeautifulSoup(html, "html.parser")
 
print(bsObj)
 
 
cs


파이썬 뷰티풀 솝으로 크롤링 하기


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from urllib.request import urlopen
from bs4 import BeautifulSoup
import json
 
code = "005930"
url = "http://companyinfo.stock.naver.com/v1/company/cF3002.aspx?cmp_cd={}&frq=0&rpt=0&finGubun=MAIN&frqTyp=0&cn=".format(code)
html = urlopen(url)
bsObj = BeautifulSoup(html, "html.parser")
 
#string to json object
jsonObject = json.loads(str(bsObj))
data = jsonObject['DATA']
 
for item in data:
    result = "{},{},{},{},{},{}".format(item['ACC_NM'], item['DATA1'], item['DATA2'], item['DATA3'], item['DATA4'], item['DATA5'])
    print(result)
cs

네이버금융 종목코드로 종목분석 데이터 불러오기




댓글을 달아 주세요