파이썬 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 답변
-
http://www.seleniumhq.org/projects/ide/
을 활용하여 해보시기 바랍니다.
- 답변주셔서 정말 감사합니다. 이 답변 보기 전에 이것 저것 시도해보니 해결 했습니다 !! ㅎㅎ str로 형변환하니까 되더라고요.... 알 수 없는 사용자 2018.1.2 12:49
댓글 입력