from bs4 import BeautifulSoup
from urllib.request import urlopen
fout = open('words_list2.txt','w')
url = 'http://endic.naver.com/?sLn=kr'
doc = urlopen(url)
web_page = BeautifulSoup(doc, 'html.parser')
word = web_page.find(attrs={'class':"tit"})
definition = web_page.find(attrs={'class':"align_line"})
fout.write(word.get_text()+':'+ definition.get_text().replace('\u200b',''))
fout.close()
答案 0 :(得分:0)
在网址http://endic.naver.com/?sLn=kr,没有类align_line
的元素,因此web_page.find(attrs={'class':"align_line"})
会返回None
,因此definition
为None
和{{ 1}}无法正常工作