제목이 혼란스럽게 들릴 수 있지만 .text()
Xpath에서 모두 별도의 읽을 수 있는 줄로 가져 오려고 합니다. 예를 들어 한 줄로 쓰여진 책은 보이지 않습니다. 나는 for 루프를 사용해 보았고 텍스트를 분할하여 10단어마다 새 줄을 추가할 생각이 있었지만 제대로 작동하지 않는 것 같습니다. 그러나 저는 파이썬을 처음 접했고 for 루프가 작동하고 .split()
작동한다고 확신 하지만 이해할 수 없습니다.
text = driver.find_element_by_xpath('//*[@id="mw-content-text"]/div[1]/p[1]')
text = text.split()
for i in text:
something
도움을 주시면 감사하겠습니다.
단어 목록을 얻으려면:
try:
text = driver.find_element_by_xpath('//*[@id="mw-content-text"]/div[1]/p[1]').text
list_of_words = text.split() # split by spaces between words
sentence = []
for word in list_of_words:
sentence.append(word)
if(len(sentence) == 10):
print(" ".join(sentence))
sentence.clear()
print(" ".join(sentence))
except:
print("Text is not found")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다