파이썬 selenium을 이용하여 파싱한 데이터가 html코드 자체로 출력이 되지 않습니다.

조회수 2356회
//from bs4 import BeautifulSoup
import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from urllib.request import urlopen
import time


try:
   url='자회사 url'
   r=requests.get(url)
   soup=BeautifulSoup(r.text,"html.parser")
   mr=soup.find(class_="ABA-article-contents" )



   driver=webdriver.Chrome()
   driver.get('http://cafe.naver.com/joonggonara')
   login=driver.find_element_by_class_name('gnb_txt')
   login.click()
   id=driver.find_element_by_id('id')
   id.send_keys('계정 아이디입력')
   pw=driver.find_element_by_id('pw')
   pw.send_keys('비밀번호입력')
   login=driver.find_element_by_class_name('btn_global')
   login.click()
   menu=driver.find_element_by_xpath('//*[@id="menuLink0"]')
   menu.click()
   cafe_write= driver.find_element_by_xpath('//*[@id="cafe-info-data"]/div[3]/a/img')
   cafe_write.click()

   driver.switch_to_frame(driver.find_element_by_id("cafe_main"))
   select=driver.find_element_by_xpath('//*[@id="boardCategory"]')
   select.click()
   select=driver.find_element_by_xpath('//*[@id="boardCategory"]/option[2]')
   select.click()
   subject=driver.find_element_by_xpath('//*[@id="subject"]')
   subject.send_keys('테스트')
   write=driver.find_element_by_xpath('//*[@id="toolbox"]/tbody/tr[4]/td')
   htmlck=driver.find_element_by_xpath('//*[@id="elHtmlMode"]')
   htmlck.click()
   ac=ActionChains(driver)
   ac.move_to_element(write)
   ac.click()
   ac.send_keys(mr)
   ac.perform()


except Exception as e:
   print(e)


finally:
   quit





코드를 설명드리면 자회사의 컨텐츠를 beautifulSoup를 이용하여 파싱한 후 변수 mr에 담아 지정한 다른 커뮤니티에 같은 글이 작성되게 함을 목적으로 작성된 코드입니다.

문제는 설정한 중고나라의 글쓰기 페이지로 넘어가서 글쓰는 영역에 mr을 출력하면 콘솔에 0 이라고 뜹니다. mr.text로 출력하면 html이 아닌 텍스트로 정상적으로 출력됩니다.

text메소드가 selnium 관련 함수일까 하여 검색해봤는데 아니더군요...html 자체로 출력되게 하려면 어떻게 해야 할까요?

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)