Skip to content
조회 수 1781 추천 수 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)
로그인 후 댓글쓰기가 가능합니다.

?

  1. 06
    Aug 2016
    12:05

    Google SpeadSheet 조건에 맞는 데이터만 참조하여 가져오기(importrange, Query)

    Category[Docs]스프레드시트 Views12979
    Read More
  2. 17
    Jul 2016
    15:02

    Mysql 백업방법 및 MYISAM to INNODB 변경방법

    Category유용한상식 Views4460
    Read More
  3. 28
    Jun 2016
    00:37

    xe 타이틀 게시판 이름 없애기

    CategoryServer Views1838
    Read More
  4. 18
    Jun 2016
    12:55

    표도르의 최강 맷집력

    Category재미재미 Views6032
    Read More
  5. 09
    May 2016
    22:46

    곡성 나홍진 감독의 숨막히는 스릴공포

    Category연예정보 Views2408
    Read More
  6. 08
    May 2016
    23:17

    판타스틱 듀오 엑소 논란이유

    Category연예정보 Views4264
    Read More
  7. 24
    Apr 2016
    22:22

    복면가왕 음악대장 하연우 노래듣기

    Category연예정보 Views51398
    Read More
  8. 19
    Apr 2016
    19:49

    XE <title>제목 - 사이트명</title> 으로 변경방법

    CategoryServer Views2078
    Read More
  9. 18
    Apr 2016
    00:31

    반기문 김대중 감시보고활동 및 비판여론

    Category연예정보 Views7991
    Read More
  10. 24
    Mar 2016
    12:55

    MySQL 5.6 my.cnf 글로벌 변수인지 세션변수인지 확인

    CategoryServer Views1539
    Read More
  11. 18
    Mar 2016
    13:22

    서버 최적화 시키기(APACHE, PHP, MYSQL, XE 압축&캐싱&버퍼)

    CategoryServer Views6240
    Read More
  12. 05
    Mar 2016
    09:06

    손정의 소프트뱅크 회장 되새겨보는 쿠팡투자

    Category종교와철학 Views7003
    Read More
  13. 14
    Feb 2016
    01:21

    이승우 데뷔골 장식한 2016년 2월 13일 후베닐A VS A-Lleida 하이라이트

    Category연예정보 Views1101
    Read More
  14. 11
    Feb 2016
    06:59

    개성공단 중단으로 경제의 득실은?

    Category주식 Views922
    Read More
  15. 01
    Feb 2016
    05:19

    백승호 골(바로셀로나 후베닐A VS 사라고사)

    Category재미재미 Views4259
    Read More
  16. 27
    Jan 2016
    23:46

    북한 수소폭탄과 장거리 미사일 실험에 주가는?

    Category주식 Views853
    Read More
  17. 07
    Jan 2016
    23:44

    트랜지스터 and MOSFET 이용한 정전류 드라이버

    Category회로도전자부품 Views5870
    Read More
  18. 30
    Dec 2015
    04:17

    다이오드

    Category회로도전자부품 Views1346
    Read More
  19. 10
    Dec 2015
    23:46

    신화실업 홍보물 - 15000원이면 지르자.

    Category주식 Views2320
    Read More
  20. 05
    Dec 2015
    07:19

    중국의 유명한 인터넷 사이트

    Category유용한상식 Views860
    Read More
Board Pagination Prev 1 ... 3 4 5 6 7 ... 16 Next
/ 16

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소