<jupyter_start><jupyter_text>class도 id도 없는 태그의 경우h1 > a[href*="---"]특정글자가 들어간 부분이 선택됨<jupyter_code>rank = content.select('td.rank')[0].text.strip()
rank
category = content.select('p.category')[0].text.strip()
category
title = content.select('h1 > a[href*="board"]')[0].text.strip()
title
songs = []
for content in contents :
    rank = content.select('td.rank')[0].text.strip()
    category = content.select('p.category')[0].text.strip()
    title = content.select('h1 > a[href*="board"]')[0].text.strip()
    sub_cnt = content.select('td.subscriber_cnt')[0].text.strip()
    view_cnt = content.select('td.view_cnt')[0].text.strip()
    video_cnt = content.select('td.video_cnt')[0].text.strip()
    hit = content.select('td.hit > strong')[0].text.strip()
    songs.append([rank, category, title, sub_cnt, view_cnt, video_cnt, hit])
songs
import pandas as pd
pd_data = pd.DataFrame(songs, columns=['Rank','Category','Title','Subscribe_CNT','View_CNT','Video_CNT','Hit'])
pd_data.to_excel('./saves/youtube_rank_scraping.xls',index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20356472795497185, 'fraction_numerical': 0.012195121951219513, 'mean_word_length': 5.973856209150327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '236114', 'license': 'Apache-2.0', 'n_tokens_mistral': 412, 'n_tokens_neox': 425, 'n_words': 55, 'path': '0625 youtube_rank_scraping.ipynb', 'repo_name': 'HyunJung-Eliana/KDT_day27_webscraping', 'size': '1066'}