반응형 분류 전체보기463 [파이썬3] python txt파일 읽기 에러 'cp949' UnicodeDecodeError: 'cp949' codec can't decode bytes in position : illegal multibyte sequence python3 부터는 ANSI 기준으로 작성된 파일만 읽을 수 있다. UTF-8로 작성된 파일은 보통 방법으로 읽을 때 에러가 난다. 2가지 방법이 있다. 1. utf-8을 붙여준다. f = open( "text.txt", "r", "utf-8" ) 2. 파일의 인코딩을 ANSI로 바꾸면 된다.해당 파일을 메모장으로 열었을 경우 [다른 이름으로 저장]에서 가능하다.밑에 보면 나와있다. 인코딩: ~~ 2017. 1. 17. [네이버] 검색어를 통한 섹션 크롤링2 from bs4 import BeautifulSoupimport urllib.parseimport urllib.request f = open("C:/Users/eyeden-FF14/Desktop/keywords.txt", 'r' )f1 = open("C:/Users/eyeden-FF14/Desktop/Naver_URL_List1.txt", 'w' , encoding='utf-8' ) keyword = f.readlines()f.close() Naver_first_URL = 'https://search.naver.com/search.naver?where=nexearch&query='Naver_behind_URL = '&sm=top_hty&fbm=0&ie=utf8' #네이버 검색할 URL 만들기 for i .. 2017. 1. 17. [파이썬3] 크롤링할 메모장 파일 읽기 #메모장 파일읽기 f = open("C:/Users/eyeden-FF14/Desktop/keywords.txt", 'r') #읽을 메모장 파일 경로 찾아 열기data = f.readlines() #파일의 모든 라인을 읽어 리스트 형태로 returnf.close() # 파일 객체 닫기 print(data) #파일의 모든 라인이 리스트 형태로 리턴되는지 확인 2017. 1. 16. [레드나이츠] 게시판 글 크롤링 import urllib.request from bs4 import BeautifulSoup plaync_URL = 'http://rk.plaync.com/board/free/view?articleId='plaync_URL_behind = '&viewMode=list' result1 = [] for num in range(145472, 145798) : num +=1 result1.append(num) for page in result1 : url = plaync_URL+str(page)+plaync_URL_behind f = urllib.request.urlopen(url) html = f.read() bs = BeautifulSoup(html, 'html.parser') post_title = bs... 2017. 1. 12. 이전 1 ··· 107 108 109 110 111 112 113 ··· 116 다음 반응형