<jupyter_start><jupyter_text>문제점선언된 `url` 내부에서 - 1~50위에 대한 web element 선언- 51~100위에 대한 데이터에 접근하기 위해 XPATH (or자바스크립트 명령어)를 실행해서 51~100위 페이지로 이동.- 51~100위 web element 선언- 1~50위의 데이터에 접근 시, 마찬가지로 stale element 에러 메세지 발생<jupyter_code>from selenium import webdriver
import pandas as pd
url = "http://www.melon.com/chart/"
driver = webdriver.Chrome()
driver.get(url)
table_50 = driver.find_elements_by_css_selector("#tb_list tbody .lst50")
table_50[0].text
driver.find_element_by_xpath("""//*[@id="tb_list"]/div/span/a""").click()
table_100 = driver.find_elements_by_css_selector("#tb_list tbody .lst100")
table_100[0].text
table_50.extend(table_100)
table_all = table_50
len(table_all)
table_all[0]
table_all[51]
melon_100 = pd.DataFrame(columns = ["Ranking", "Song", "Artist", "Album"])
melon_100<jupyter_output><empty_output><jupyter_text>Get all data<jupyter_code># get all data and store

for table in tables:
    
    rank = table.find_element_by_css_selector(".rank").text
    song = table.find_element_by_css_selector(".wrap_song_info .ellipsis.rank01 a").text
    artist = table.find_element_by_css_selector(".wrap_song_info .ellipsis.rank02 a").text
    album = table.find_element_by_css_selector(".wrap_song_info .ellipsis.rank03 a").text
    
    data = {"Ranking" : rank, 
            "Song" : song, 
            "Artist" : artist, 
            "Album" : album, }
    
    melon_100.loc[len(melon_100)] = data
    
melon_100 = melon_100.set_index('Ranking')
driver.close()
melon_100.to_csv('melon_chart_100')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1313915857605178, 'fraction_numerical': 0.05048543689320388, 'mean_word_length': 4.856060606060606, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '384685', 'license': 'MIT', 'n_tokens_mistral': 700, 'n_tokens_neox': 696, 'n_words': 110, 'path': '2_python_Packages_Libraries/6_selenium/04_real_case_practice/02_melon_chart_inrealtime/01_melon_chart_table_scraping.ipynb', 'repo_name': 'lucaseo/TIL', 'size': '1545'}