나는 BeautifulSoup를 사용하여 텍스트 크롤러를 만들고 있습니다. 그러나이 코드를 실행하면 오류 코드가 표시됩니다.BeautifulSoup 사용
Traceback (most recent call last):
File "D:\Python27\Crawling.py", line 33, in <module>
text = content.get_text()
AttributeError: 'NoneType' object has no attribute 'get_text'
해결 방법을 알려 주시면 대단히 감사하겠습니다.
import urllib
from bs4 import BeautifulSoup
import xml.dom.minidom
keyWord = raw_input("Enter the key-word : ")
#Enter my Search KeyWord
address = "http://openapi.naver.com/search?key=8d4b5b7fef7a607863013302754262a3&query=" + keyWord + "&display=5&start=1&target=kin&sort=sim"
search_result = urllib.urlopen(address)
raw_data = search_result.read()
parsed_result = xml.dom.minidom.parseString(raw_data)
links = parsed_result.getElementsByTagName('link')
source_URL = links[3].firstChild.nodeValue
#The number 3 has no meaning, it has 0 to 9 and I just chose 3
page = urllib.urlopen(source_URL).read()
#save as html file
g = open(keyWord + '.html', 'w')
g.write(page)
g.close()
#open html file
g = open(keyWord + '.html', 'r')
bs = BeautifulSoup(g)
g.close()
content = bs.find(id="end_content")
text = content.get_text()
#save as text file
h = codecs.open(keyWord + '.txt', 'w', 'utf-8')
h.write(keyWord + ' ')
h.write(text)
print "file created"
그 오류는 간단하다 : 발견()가 아무것도 찾을 수없는 경우 없음 반환'content' 블록을 반환 * nothing *, 그래서 당신은'get_text'를 사용할 수 없습니다. – Manhattan
감사합니다, 신의 축복이 – user3473222