-2
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()
5
  • 1
    Why do you think you have a valid result in the previous line? Commented May 3, 2016 at 12:22
  • i don`t know what you mean... Commented May 3, 2016 at 12:37
  • Have you read your code? Commented May 3, 2016 at 12:38
  • yes. i just think that 'class':"tit" this type is not correct. so i want to know how to web crawling at this site Commented May 3, 2016 at 12:40
  • There are dozens of questions and answers with this exact or near exact error message. Please do a little research before asking a new question. If your question is truly unique, cite what research you've done and why the other answers aren't applicable. Commented May 3, 2016 at 13:35

1 Answer 1

0

At the url http://endic.naver.com/?sLn=kr there's no element with the class align_line so web_page.find(attrs={'class':"align_line"}) returns None and therefore definition is None and definition.get_text() isn't going to work

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.