<s> import requests <EOL> from bs4 import BeautifulSoup <EOL> import json <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> index_page_url = "<STR_LIT>" <EOL> soup = BeautifulSoup ( requests . get ( index_page_url ) . text ) <EOL> stations = soup . select ( '<STR_LIT>' ) <EOL> station_data = { } <EOL> for station_el in stations : <EOL> station_name_el = station_el . findNext ( '<STR_LIT>' ) . findNext ( '<STR_LIT>' ) <EOL> station_class_el = station_name_el . findNext ( '<STR_LIT>' ) <EOL> station_data [ station_el . text . strip ( ) ] = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" . join ( station_name_el . text . split ( "<STR_LIT:U+002C>" ) [ : - <NUM_LIT:1> ] ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) . replace ( "<STR_LIT:\t>" , "<STR_LIT>" ) . strip ( ) , <EOL> "<STR_LIT:state>" : station_name_el . text . split ( "<STR_LIT:U+002C>" ) [ - <NUM_LIT:1> ] . strip ( ) , <EOL> "<STR_LIT:class>" : station_class_el . text . split ( ) [ <NUM_LIT:1> ] . strip ( ) , <EOL> } <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> json . dump ( station_data , f ) </s>
