본문 바로가기
Python

[네이버] 웹툰 스크래핑

by 퍼포먼스마케팅코더 2017. 1. 6.
반응형

#파이썬에서 바로 네이버 웹툰 목록 스크래핑


파이썬 버전 :  3.6.xxxx

Beautiful Soup 버전: 4.xxxx

sublime text3 툴 사용


import urllib.request

from bs4 import BeautifulSoup


html = urllib.request.urlopen('http://comic.naver.com/webtoon/weekday.nhn')

soup = BeautifulSoup(html)

titles = soup.find_all('a','title')

for title in titles:

print('title:{0:10s} link:{1:20s}\n'.format(title['title'], title['href']))



#스크래핑 내용을 메모장에 저장 


import urllib.request

from bs4 import BeautifulSoup


f = open("C:/Python/새파일.txt", 'w')

html = urllib.request.urlopen('http://comic.naver.com/webtoon/weekday.nhn')

soup = BeautifulSoup(html)

titles = soup.find_all('a','title')

for title in titles:

      data = 'title:{0:10s} link:{1:2s}\n'.format(title['title'], title['href'])

      f.write(data)

f.close()



반응형

댓글