Skip to content
조회 수 1780 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

 

 

import time #time 명령어 사용하기 
from selenium import webdriver #셀레니움 사용하기 
from selenium.webdriver.common.keys import Keys #키보드 입력하기 위한 설정
 
# 크롬 웹드라이버를 이용하여 크롬을 실행
driver = webdriver.Chrome("C:\chromedriver.exe")
 
driver.get("https://finance.naver.com/item/main.nhn?code=006980"#네이브로 이동 
time.sleep(1)

# html elemnt id가 stock_items 인 것을 찾습니다. 
inputElement = driver.find_element_by_id("stock_items"
#time.sleep(1)

#종목 검색창에 문배철강을 입력 
inputElement.send_keys("문배철강"
#time.sleep(1)

# 입력한 문배철강 검색내용을 서버로 보냄
inputElement.submit()
time.sleep(1)
 
#body에 PAGE_DOWN 키를 입력하여 스크롤을 아래로 내린다.
body = driver.find_element_by_css_selector("body")
body.send_keys(Keys.PAGE_DOWN)
time.sleep(1)
 
# 검색된 리스트 중 링크 텍스트에 "종목분석"이 포함된 것을 찾음 
continue_link = driver.find_element_by_partial_link_text("종목분석")
#time.sleep(1)
 
#'종목분석' 해당 링크를 클릭함 
continue_link.click() 
time.sleep(1)

#파이썬 requests 모듈은 간편한 HTTP 요청처리를 위해 사용하는 모듈로 별도로 설치해 주어야 한다.
import requests #pip3 install requests
from bs4 import BeautifulSoup #뷰티풀솝을 사용하기
 
#driver = webdriver.Chrome()  => 크롬드라이버 실행준비
#print (driver.current_url)  => 크롬창의 url 불러오기
 
html = requests.get(driver.current_url)
bs_html = BeautifulSoup(html.content,"html.parser")


 
driver.quit()

#bs의 select 사용법
    #soup.select('태그')
    #soup.select('.클래스명') 혹은 ('태그.클래스명')
    #soup.select('#아이디명') 혹은 ('태그#아이디명')
    #soup.select('태그 > 자식태그')
    #soup.select('태그 자손태그')
 
# id가 headline0인 태그의 자손 중 li 크롤링
    #title = soup.select('#headline0 li')

#현재가
today_value = bs_html.select("span.blind")[12]
print(today_value.text)
 
#시가총액
#total_value = bs_html.find('em', id="_market_sum").string
total_value = bs_html.find("em", { "id" : "_market_sum" }).get_text(" "strip=True)
print(total_value)
 
#PER
per_value = bs_html.find("em", {"id" : "_per"}).get_text(" "strip=True)
print(per_value)
 
#PBR
pbr_value = bs_html.find("em", { "id" : "_pbr" }).get_text(" "strip=True)
print(pbr_value)
 
#EPS
#eps_value = bs_html.select("em")[70]
eps_value = bs_html.find("em", { "id" : "_eps" }).get_text(" "strip=True)
print(eps_value)
 
#BPS
#bps_value = bs_html.select("table[5].per_table tr[2] td em[1]")
bps_table_value = bs_html.find_all("table", {"class" : "per_table"})
#bps_value = bps_table_value.find_all("tr")
bps_table_value = bps_table_value.select("")
print(bps_table_value)

#배당수익률
dvr_value = bs_html.find("em", { "id" : "_dvr" }).get_text(" "strip=True)
print(dvr_value)
로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
137 컴퓨터잡담 로블록스 스튜디오 파트속성 2021.09.28 3085
136 [Docs]스프레드시트 구글 스프레드시트 쿼리 사용하기 #2 2021.09.26 3052
135 파이썬 파이썬 키움openAPI 보유종목 종목리스트 피라미드 매수주문하기 2021.09.16 3032
134 컴퓨터잡담 파이썬 Beautifulsoup html의 특정 주소만 가져오기 file 2021.06.14 2986
133 Server XE 스케치북 모바일 비회원 댓글쓰기에서 홈페이지 이메일 기입란 삭제하기 2016.04.08 2980
132 파이썬 파이썬 변수내용 문자열 자르기 특이한 점 2021.09.27 2965
131 컴퓨터잡담 파이썬의 IF문 사용시 실행값에서 오류발생시 진행하는 예외처리 방법 2021.06.15 2872
130 컴퓨터잡담 한글입력이 안될때(how to hangul ...) file 2021.01.08 2839
129 Server XE PC에서 모바일화면 출력방법 file 2016.09.08 2836
128 Server [php.ini]XE 신디케이션 OpenSSL 오류문구 해결방법 file 2016.08.25 2816
127 Server ECS P43T-AD3, Asus C381GM, Driver(두번째 사용했던 서버 드라이버) file 2016.04.12 2804
126 Server 아파치 캐시 설정 이후 잦은 아파치 자동멈춤 현상 원인분석 3 2016.03.23 2770
125 파이썬 파이썬 datetime 모듈로 초간단 날짜 표현하기 2021.09.11 2714
124 컴퓨터잡담 크롬 캐시파일 삭제방법(Chrome cache file delete) file 2016.11.27 2708
123 컴퓨터잡담 동영상 자르기 프로그램 file 2014.04.14 2704
122 WindowsTip 응용 프로그램 구성 이 올바르지 않기 때문에 이 응용 프로그램 을 시작 하지 못했습니다 2015.02.06 2687
121 [Docs]스프레드시트 구글 스프레드시트 스크립트를 사용하여 지메일로 이메일을 보내기 2023.03.10 2678
120 WindowsTip 윈도우 하드에서 설치하기 2015.02.17 2667
119 컴퓨터잡담 파이썬 자주 발생되는 에러(오류) 대처방법 file 2021.06.05 2663
118 Server innodb_use_sys_malloc to FALSE 2016.08.24 2637
Board Pagination Prev 1 ... 38 39 40 41 42 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소