# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

from bs4 import BeautifulSoup
html = open('webtoon_list.html', 'rt').read()
soup = BeautifulSoup(html)

# +
from urllib import parse

for a in soup.select('a.title'):
    href = a['href']
# -

for img in soup.select('div.thumb img'):
    print(img['title'])
    print(img['src'])

for div_thumb in soup.select('div.thumb'):
    src = div_thumb.select_one('img[title]')['src']
    title = div_thumb.parent.select_one('a.title').get_text(strip=True)
    print(title)
    print(src)

# +
webtoon_info_dict = {}

def webtoon_info(title):
    soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())

    a = soup.select_one('a.title[title*="{}"]'.format(title))
    href = a['href']
    li = a.parent
    img = li.select_one('img')
    thumbnail = img['src']

    return {
        'title': title,
        'link': href,
        'thumbnail': thumbnail,
    }

webtoon_info('신의')


# -

def webtoon_info(title):
    soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())
    a_list = soup.select('a.title[title*="{}"]'.format(title))

    results = []

    for a in a_list:
        href = a['href']
        thumbnail = a.parent.select_one('img')['src']
        title = a.get_text(strip=True)

        cur_info = {
            'title': title,
            'link': href,
            'thumbnail': thumbnail,
        }
        results.append(cur_info)
    return results
webtoon_info('신')

# +
webtoon_info_dict = {}

soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())
for div_thumb in soup.select('div.thumb'):
    a = div_thumb.parent.select_one('a.title')
    link = a['href']
    title = a.get_text(strip=True)
    src = div_thumb.select_one('img[title]')['src']
    
    webtoon_info_dict[title] = {
        'link': link,
        'thumbnail': src,
    }

def webtoon_info(title):
    result_dict = {}
    for key, value in webtoon_info_dict.items():
        if title in key:
            result_dict[key] = value
    return result_dict

webtoon_info('신의')

# +
webtoon_info_dict = {}

soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())
for div_thumb in soup.select('div.thumb'):
    a = div_thumb.parent.select_one('a.title')
    link = a['href']
    title = a.get_text(strip=True)
    src = div_thumb.select_one('img[title]')['src']
    
    webtoon_info_dict[title] = {
        'link': link,
        'thumbnail': src,
    }

def webtoon_info(title):
    result_dict = {}
    for key, value in webtoon_info_dict.items():
        if title in key:
            result_dict[key] = value
    return result_dict

webtoon_info('신의')

# +
webtoon_info_dict = {}
soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())
for div_thumb in soup.select('div.thumb'):
    a = div_thumb.parent.select_one('a.title')
    link = a['href']
    title = a.get_text(strip=True)
    src = div_thumb.select_one('img[title]')['src']
    
    webtoon_info_dict[title] = {
        'link': link,
        'thumbnail': src,
    }
    
def webtoon_info(title):
    result_dict = {}
    for key, value in webtoon_info_dict.items():
        if title in key:
            result_dict[key] = value
    return result_dict

webtoon_info('유미')

# +
webtoon_info_dict = {}

soup = BeautifulSoup(open('webtoon_list.html').read())
for div_thumb in soup.select('div.thumb'):
    a = div_thumb.parent.select_one('a.title')
    link = a['href']
    title = a.get_text(strip=True)
    src = div_thumb.select_one('img[title]')['src']
    
    webtoon_info_dict[title] = {
        'link': link,
        'thumbnail': src,
    }

    
def webtoon_info(title):
    result_dict = {}
    for key, value in webtoon_info_dict.items():
        if title in key:
            result_dict[key] = value
    return result_dict

webtoon_info('유미')

# +
webtoon_info_dict = {}

soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())
for div_thumb in soup.select('div.thumb'):
    a = div_thumb.parent.select_one('a.title')
    link = a['href']
    title = a.get_text(strip=True)
    src = div_thumb.select_one('img[title]')['src']
    
    webtoon_info_dict[title] = {
        'link': link,
        'thumbnail': src,
    }
    
def webtoon_info(title):
    result_dict = {}
    for key, value in webtoon_info_dict.items():
        if title in key:
            result_dict[key] = value
    return result_dict

webtoon_info('유미')

# +
webtoon_info_dict = {}

soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())
for div_thumb in soup.select('div.thumb'):
    a = div_thumb.parent.select_one('a.title')
    link = a['href']
    title = a.get_text(strip=True)
    src = div_thumb.select_one('img[title]')['src']
    
    webtoon_info_dict[title] = {
        'link': link,
        'thumbnail': src,
    }
    
def webtoon_info(title):
    result_dict = {}
    for key, value in webtoon_info_dict.items():
        if title in key:
            result_dict[key] = value
    return result_dict

webtoon_info('유미')

# +
webtoon_info_dict = {}

soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())
for div_thumb in soup.select('div.thumb'):
    a = div_thumb.parent.select_one('a.title')
    link = a['href']
    title = a.get_text(strip=True)
    src = div_thumb.select_one('img[title]')['src']
    
    webtoon_info_dict[title] = {
        'link': link,
        'thumbnail': src,
    }
    
def webtoon_info(title):
    result_dict = {}
    for key, value in webtoon_info_dict.items():
        if title in key:
            result_dict[key] = value
    return result_dict

webtoon_info('신의')

# +
webtoon_info_dict = {}
soup = BeautifulSoup(open('webtoon_list.html', 'rt').read())
for div_thumb in soup.select('div.thumb'):
    a = div_thumb.parent.select_one('a.title')
    link = a['href']
    title = a.get_text(strip=True)
    src = div_thumb.select_one('img[title]')['src']
    
    webtoon_info_dict[title] = {
        'link': link,
        'thumbnail': src,
    }
    
def webtoon_inf(title):
    result_dict = {}
    for key, value in webtoon_info_dict.items():
        if title in key:
            result_dict[key] = value
    return result_dict

webtoon_info('신의')
# -



StarcoderdataJupyterScriptsDedupFiltered