示例#1
0
文件: crawler.py 项目: Ryanden/TIL
    def choice(cls):

        print('현재 검색결과를 출력합니다.')
        cls.show_request_list()

        print(f'상위 목록에서 열람을 희망하는 웹툰 번호를 선택 해 주세요.')
        user_request = input(f'선택 :')

        # 유저의 입력을 받아 요청과 매치되는 인스턴스를 리스트에서 추출
        for i, webtoon in enumerate(cls.request_list):
            if user_request != str(i + 1):
                continue
            else:
                # 목록에서 선택한 번호와 요청한 번호가 같은 인스턴스만 할당
                selected_webtoon = webtoon
                break

        print('1. 웹툰 정보 보기 \n' '2. 웹툰 저장하기 \n' '3. 다른 웹툰 검색해서 선택하기 ')
        user_request = input(f'선택 :')

        if user_request is '1':
            # 웹툰클래스에 요청한 인스턴스의 id를 매개변수로 전달하여 인스턴스 생성
            webtoon_info = Webtoon(webtoon_id=selected_webtoon.webtoon_id)

            # webtoon_info 인스턴스에 기본 속성을 셋팅
            # webtoon_info.html프로퍼티로 webtoon_info 인스턴스의 html을 자신의 속성으로 사용
            webtoon_info.html

            # webtoon_info의 title프로퍼티로 title, author, description을 셋팅
            webtoon_info.title

            webtoon_info.episode_list

            # webtoon_info 인스턴스의 기본정보를 출력
            webtoon_info.show_info()

            print(f'다른정보를 조회하려면 1번, 종료하려면 2번을 입력해주세요.')
            user_request = input(f'선택 :')

            # 정보를 출력하고 다시 메서드 호출로 돌아감
            if user_request is '1':
                cls.choice()
            else:
                print('이용해주셔서 감사합니다. 크롤러를 종료합니다.')

        elif user_request is '2':
            pass
        elif user_request is '3':
            # search 메서드 호출로 다른 웹툰의 정보를 사용자에게 입력받도록 함
            cls.search()
        else:
            # 1,2,3번 만 입력받도록 함
            print('입력이 올바르지 않습니다. \n' '1,2,3 번의 메뉴에 해당하는 번호를 입력 해 주세요.')
            cls.choice()
def ini():
    """
    초기 메서드
    :return:
    """
    while True:
        # 제목으로 웹툰 검색
        print('---------------------------------')
        keyword = input('검색할 웹툰명을 입력해주세요 :')
        result_lists = Webtoon.search_webtoon(keyword)
        # 검색 키워드의 결과가 없는 경우
        if not result_lists:
            print(f'일치하는 웹툰이 없습니다. 다시 입력해주세요\n')
            continue
        break

    # 검색한 키워드에 해당하는 웹툰 리스트 출력
    select_webtoon = print_search_list(result_lists)

    # 웹툰을 고르고 난 후 웹툰 정보/저장/ 관련 메서드 실행
    webtoon_select(select_webtoon)
示例#3
0
def search_main():
    search_input = input('검색할 웹툰명을 입력해주세요 : ')
    webtoon_find = SearchWebtoon()
    webtoon_find.search_webtoon(search_input)
    choice_input1 = input('선택 : ')
    print(
        f'현재 "{webtoon_find.search_list[int(choice_input1)-1]}" 웹툰이 선택되어 있습니다.'
    )
    print('1. 웹툰 정보 보기')
    print('2. 웹툰 저장하기')
    print('3. 다른 웹툰 검색해서 선택하기')
    choice_input2 = input('선택 : ')
    while 1:
        if choice_input2 == '1':
            print('1번을 선택했습니다')
            webtoon1 = Webtoon(
                webtoon_find.webtoon_id_list[int(choice_input1) - 1])
            webtoon1.webtoon_html()
            webtoon1.set_info()
            return search_main()

        elif choice_input2 == '2':
            print('2번은 선택했습니다')
            webtoon1 = Webtoon(
                webtoon_find.webtoon_id_list[int(choice_input1) - 1])
            webtoon1.webtoon_html()
            webtoon1.set_info()
            for episode in webtoon1.crawler_episode_list():
                print(f'======{episode} 다운로드 중=====')
                episode.download_all()
            print('저장이 완료되었습니다.')
            return search_main()

        elif choice_input2 == '3':
            print('3번을 선택했습니다')
            return search_main()

        else:
            print('다시 선택해주세요')
            choice_input2 = input('선택 : ')
示例#4
0
from urllib.parse import urlparse, parse_qs
import requests
from bs4 import BeautifulSoup
from utils import Webtoon

url = 'http://comic.naver.com/webtoon.nhn'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
webtoon_list = set()

daily_all = soup.select_one('.list_area.daily_all')
days = daily_all.select('div.col')
for day in days:
    items = day.select('li')
    for item in items:
        img_url = item.select_one('div.thumb').a.img['src']
        title = item.select_one('a.title').get_text(strip=True)

        url_webtoon = item.select('a.title')['href']
        parse_result = urlparse(url_webtoon)
        queryset = parse_qs(parse_result.query)
        title_id = queryset['titleId'][0]

        webtoon = Webtoon(title_id=title_id, img_url=img_url, title=title)
        webtoon_list.add(webtoon)

webtoon_list = sorted(list(webtoon_list), key=lambda x: x.title)
for webtoon in webtoon_list:
    print(webtoon.title)
示例#5
0
def search_main():
    search_input = input('검색할 웹툰명을 입력해주세요 : ')
    webtoon_find = SearchWebtoon()
    webtoon_find.search_webtoon(search_input)
    choice_input1 = input('선택 : ')
    print(
        f'현재 "{webtoon_find.search_list[int(choice_input1)-1]}" 웹툰이 선택되어 있습니다.'
    )
    print('1. 웹툰 정보 보기')
    print('2. 웹툰 저장하기')
    print('3. 다른 웹툰 검색해서 선택하기')
    choice_input2 = input('선택 : ')
    while 1:
        if choice_input2 == '1':
            print('1번을 선택했습니다')
            webtoon1 = Webtoon(
                webtoon_find.webtoon_id_list[int(choice_input1) - 1])
            webtoon1.get_html()
            webtoon1.set_info()
            print(f'{webtoon1.title}')
            print(f'    작가명 : {webtoon1.author}')
            print(f'    설명 : {webtoon1.description}')
            print(f'    총 연재회수 : {webtoon1.num_of_episodes}')
            return search_main()

        elif choice_input2 == '2':
            print('2번을 선택했습니다')
            webtoon1 = Webtoon(
                webtoon_find.webtoon_id_list[int(choice_input1) - 1])
            webtoon1.get_html()
            webtoon1.set_info()
            print(f'웹툰 저장 시작 (총 {webtoon1.num_of_episodes}화)')
            for episode in webtoon1.crawl_episode_list():
                print(f'======{episode} 다운로드 중=====')
                episode.download_all_images()
            print('저장이 완료되었습니다.')
            return search_main()

        elif choice_input2 == '3':
            print('3번을 선택했습니다')
            return search_main()

        else:
            print('다시 선택해주세요')
            choice_input2 = input('선택 : ')
示例#6
0
            #'/webtoon/list.nhn?titleId=679519&weekday=thu',



if __name__=='__main__':
    while(True):
        print('Ctrl=c 로 종료합니다.')
        webtoon_name =input('검색할 웹툰명을 입력해주세요:')
        result_list=title_crawler(str(webtoon_name))
        #print(result_list)

        for i, name in enumerate(result_list):
            print(f'{i}. {name[1]}')
        choosed_num=input('선택:')

        webtoon=Webtoon((result_list[int(choosed_num)])[0])
        print(webtoon.title)
        print('     작가명: ',webtoon.author)
        print('     설명: ', webtoon.description)


        print(f'현재 "{webtoon.title}" 웹툰이 선택되어 있습니다.' )
        print(f'0. 웹툰 정보 보기')
        print(f'1. 웹툰 저장하기 ')
        print(f'2. 다른 웹툰 검색해서 선택하기')
        choosed_op = input('선택: ')

        print(type(choosed_op))
        if choosed_op == '0':
            print(webtoon.title)
            print('     작가명: ', webtoon.author)