엑셀로 저장 웹 컨텐츠

셀레늄 수입 webdriver에서
시간 가져 오기 잠에서
selenium.common.exceptions에서 예외 : NoSuchElementException를 가져올
통합 문서 openpyxl 수입에서

드라이버 webdriver.Chrome = ()
driver.get ( "https://tieba.baidu.com/index.html")

# 위치 검색 상자
driver.find_element_by_xpath ( '// 입력 [@ ID = "WD1"]'). Send_keys ( " 일 마오의 책")

위치 검색 버튼을 #
driver.find_element_by_xpath ( '// A [텍스트 ( ) = " 전체 검색 바"]'). 클릭과 ()
SLEEP. (3)

# 열기 Excel 스프레드
WB = 통합 ()
WS = wb.active
ws.append ([ "제목", "콘텐츠"])
행 2 =
ROW2 = 2

: 진정한 동안
title_list = 목록 ()
시도 :
#定位标题
all_title = driver.find_elements_by_xpath ( '// 범위 [클래스 @ = "p_title"]')
all_content = driver.find_elements_by_xpath ( '// DIV [클래스 @ = "p_content" ])
all_title의 제목 :
ws.cell (행 1 title.text)
인쇄 ( "保存标题到엑셀表格中")
로우 로우 + 1 =

대한 all_content의 내용 :
ws.cell (ROW2, 2, content.text)
인쇄 ( "엑셀 형식으로 저장")
. ROW2 1 + = ROW2

wb.save ( "./ data.xlsx")
#定位下一页
driver.find_element_by_xpath ( '// A [클래스 @ = "다음"]'). ()을 클릭
절전 (3)

E로는 NoSuchElementException을 다음을 제외
휴식을

추천

출처www.cnblogs.com/mary-ding/p/12190444.html