π CSS
- HTML λ¬Έμμμ μ€νμΌμ κ΄λ ¨λ λΆλΆμ λ³λλ‘ λΆλ¦¬
- μ¬μ© μ ν
1) νκ·Έ λ΄λΆ μ½μ ν : HTML νκ·Έ λ΄μ style μμ± μ΄μ©
2) λ΄λΆ μ€νμΌ μνΈ : headνκ·Έ μ styleνκ·Έ λ΄λΆμ μμ± μμ±
3) μΈλΆ μ€νμΌ μνΈ : cssνμΌ μΈλΆμ μ μ₯- ν΄λμ€ μ νμ : λμΌν νκ·ΈλλΌλ λ€λ₯Έ μ€νμΌμ μ μ©νκ³ μΆμ λ μ νμμ classμμ± μΆκ°
- id μ νμ : id μμ±μ΄ μλ νΉμ νκ·Έμ λ΄μ©μλ§ ν΄λΉ μ€νμΌ μ§μ , ν λ¬Έμμ νλ²λ§ μ¬μ©κ°λ₯
<html>
<head>
<title>css μ μ©ν λ¬Έμ₯ ν¬λ§·</title>
<style type="text/css">
P.content1 {font-family:κΆμ; color:red;}
.content2 {font-family:κ΅΄λ¦Ό; background:yellow;}
</style>
</head>
<body>
<p class="content1">첫λ²μ§Έλ¬Έλ¨</p>
<p class="content2">λλ²μ§Έλ¬Έλ¨</p>
<p>μΈλ²μ§Έλ¬Έλ¨</p>
</body>
</html>
<html>
<head>
<title>css μ μ©ν λ¬Έμ₯ ν¬λ§·</title>
<style type="text/css">
P#content1 {font-family:κΆμ; color:red;}
#content2 {font-family:κ΅΄λ¦Ό; background:yellow;}
</style>
</head>
<body>
<p id="content1">첫λ²μ§Έλ¬Έλ¨</p>
<p id="content2">λλ²μ§Έλ¬Έλ¨</p>
<p>μΈλ²μ§Έλ¬Έλ¨</p>
</body>
</html>
π κ²°κ³Όλ classλ₯Ό μ΄μ©ν κ²κ³Ό κ°λ€.
from urllib.request import urlopen
from bs4 import BeautifulSoup
import time
import re
import pandas as pd
# 1) λ°μ΄ν°νλ μ μμ±
data = pd.DataFrame(columns=['μ€ν
μ΄μ
λͺ
','μμΉ','μνμ 보','μλ','κ²½λ'])
# 2) νμ μ¬μ΄νΈ μ μ μ£Όμ : https://new.tashu.or.kr/stationList.do
url = 'https://new.tashu.or.kr/stationList.do'
# 3) url μ μνμ¬ HTMLκ°μ Έμ€κΈ°
html = urlopen(url)
# 4) HTML νκ·Έ νμ±(parsing)νμ¬ λ³ν
bsObject = BeautifulSoup(html, 'html.parser', from_encoding='UTF-8')
# 5) νμ μ λ₯μ₯ μ λ³΄κ° μλ tableλ§ κ°μ Έμ€κΈ°
table = bsObject.find_all('table', {'class','board-tp-01 stationtable'})
# 6) μμΈμ 보 μΆμΆνκΈ°
# 6-1) tableλ΄μ trλ₯Ό μ°ΎκΈ°
tr = table[0].find_all('tr')
# 6-2) 첫 tr(ν
μ΄λΈμ 컬λΌμ 보)μ μ μΈ
tr = tr[1:len(tr)]
# 6-3) νμ μ λ₯μ₯ μμΈ μ 보 μΆμΆ
for index_tr in range(0, len(tr)):
td = tr[index_tr].find_all('td')
# μ₯μ
# ex) 1.무μμ μκ΄μ
ꡬ(νμμΉκ°μ₯) -> 무μμ μκ΄μ
ꡬ(νμμΉκ°μ₯)
station = td[0].text.split('.')[1]
# μμΉ
location = td[1].text
# μν
condition = td[2].text
# μ’ν μΆμΆ
# μλ Latitude
lat = td[3].button.attrs['data-lat']
# κ²½λ Longitude
lon = td[3].button.attrs['data-ltd']
# 7) νμ μ λ₯μ₯ μμΈ μ 보 Dataframeμ λ΄κΈ°(append)
data = data.append({'μ€ν
μ΄μ
λͺ
': station,
'μμΉ':location,
'μνμ 보':condition,
'μλ':lat,
'κ²½λ':lon},ignore_index=True)
print('Complets of ' + station)
print('----------------------------------------------------------------')
print(data)
data.to_csv('TASHU.csv', encoding='utf-8-sig')
# λ°μ΄ν° μ€λΉνκΈ°
df = pd.read_csv('/content/TASHU.csv')
df.head()
import folium
# 1) νμ μ λ₯μ₯ μμΉ κΈ°λ°μΌλ‘ μ€μ¬μ’ν μ€μ
t_map = folium.Map(location=[df['μλ'].mean(),df['κ²½λ'].mean()], zoom_start=14)
# 2) νμ μ λ₯μ₯μ μνμ λ°λΌμ Markerλ₯Ό λ€λ₯Έ μμΌλ‘ νμ
# df.μνμ 보.unique() -> μ μ:νλμ, NETWORK μλ¬ : λΉ¨κ°μ
condition = df.μνμ 보 # df['μνμ 보']
# 3) νμ μ λ₯μ₯ Marker μΆκ°νκΈ°
for index_draw in range(0, len(condition)):
if condition[index_draw] == 'μ μ':
folium.Marker([df.loc[index_draw, 'μλ'], df.loc[index_draw, 'κ²½λ']],
popup='<pre>'+df.loc[index_draw, 'μ€ν
μ΄μ
λͺ
']+'</pre>', icon=folium.Icon(color='blue', icon='info-sign')).add_to(t_map)
elif condition[index_draw] == 'NETWORK μλ¬':
folium.Marker([df.loc[index_draw, 'μλ'], df.loc[index_draw, 'κ²½λ']],
popup='<pre>'+df.loc[index_draw, 'μ€ν
μ΄μ
λͺ
']+'</pre>', icon=folium.Icon(color='red', icon='info-sign')).add_to(t_map)
t_map
β tiles='Stamen Terrain'μΆκ°
t_map = folium.Map(location=[df['μλ'].mean(),df['κ²½λ'].mean()], zoom_start=14, tiles='Stamen Terrain')
β tiles='Stamen Toner'μΆκ°
β tiles='Stamenwatercolor'μΆκ°
π λ€λ₯Έ λ€μν tiles -> https://deparkes.co.uk/2016/06/10/folium-map-tiles/ μ°Έκ³
popup='<pre>'+df.loc[index_draw, 'μ€ν
μ΄μ
λͺ
']+'</pre>', icon=folium.Icon(color='red', icon='fa-bicycle', prefix='fa')).add_to(t_map)
ν΄λΉλΆλΆ iconμ bicycleλ‘ λ³κ²½ https://fontawesome.com/v4/icon/bicycle
from urllib.request import urlopen
from bs4 import BeautifulSoup
import time
import re
import pandas as pd
import folium
# 1) λ°μ΄ν°νλ μ μμ±
data = pd.DataFrame(columns=['μ€ν
μ΄μ
λͺ
','μμΉ','μνμ 보','μλ','κ²½λ'])
# 2) μ΄μΈλ§ μ¬μ΄νΈ μ μ μ£Όμ : https://www.sejongbike.kr/userStationAction.do?process=stationTotalList&menu=21
url = 'https://www.sejongbike.kr/userStationAction.do?process=stationTotalList&menu=21'
# 3) url μ μνμ¬ HTMLκ°μ Έμ€κΈ°
html = urlopen(url)
# 4) HTML νκ·Έ νμ±(parsing)νμ¬ λ³ν
bsObject = BeautifulSoup(html, 'html.parser', from_encoding='UTF-8')
# 5) μ λ₯μ₯ μ λ³΄κ° μλ tableλ§ κ°μ Έμ€κΈ°
table = bsObject.find_all('table', {'class','content_table'})
# 6) μμΈμ 보 μΆμΆνκΈ°
# 6-1) tableλ΄μ trλ₯Ό μ°ΎκΈ°
tr = table[0].find_all('tr')
# 6-2) 첫 tr(ν
μ΄λΈμ 컬λΌμ 보)μ μ μΈ
tr = tr[1:len(tr)]
# 6-3) μ λ₯μ₯ μμΈ μ 보 μΆμΆ
for index_tr in range(0, len(tr)):
td = tr[index_tr].find_all('td')
# μ₯μ
station = td[0].text.split('.')[1]
# μμΉ
location = td[1].text
# μν
condition = td[2].text
# μ’ν μΆμΆ
# μλ Latitude
lat = td[3].find('a').attrs['onclick'].split('\'')[3]
# κ²½λ Longitude
lon = td[3].find('a').attrs['onclick'].split('\'')[5]
# 7) μ λ₯μ₯ μμΈ μ 보 Dataframeμ λ΄κΈ°(append)
data = data.append({'μ€ν
μ΄μ
λͺ
': station,
'μμΉ':location,
'μνμ 보':condition,
'μλ':lat,
'κ²½λ':lon},ignore_index=True)
data.to_csv('sejongbike.csv', encoding='utf-8-sig')
df = pd.read_csv('/content/sejongbike.csv')
# 1) μ λ₯μ₯ μμΉ κΈ°λ° μ€μ¬μ’ν μ€μ
s_map = folium.Map(location = [df['μλ'].mean(), df['κ²½λ'].mean()], zoom_start = 14) # meanμ νκ·
# 2) μ λ₯μ₯μ μνμ λ°λΌμ Markerλ₯Ό λ€λ₯Έ μμΌλ‘ νμ-> μ μ-νλμ, λ€νΈμν¬ μ€λ₯-λΉ¨κ°μ
condition = df.μνμ 보 # df.μνμ 보 == df['μνμ 보'], 컬λΌλ΄λΆμ κ°λ€μ μ’
λ₯λ₯Ό 보λ λ°©λ² unique : df.μνμ 보.unique()
# 3) μ λ₯μ₯ Marker μΆκ°νκΈ°
for index_draw in range(0, len(condition)): # condition λ³μλ₯Ό μ μΈν μ΄μ , μνμ λ³΄κ° μλ κ²½μ°κΉμ§ 컀λ²νκΈ° μν΄
if condition[index_draw] == 'μ μ':
folium.Marker([df.loc[index_draw, 'μλ'], df.loc[index_draw, 'κ²½λ']],
popup = '<pre>'+df.loc[index_draw, 'μ€ν
μ΄μ
λͺ
']+ '</pre>', icon=folium.Icon(color = 'blue', icon = 'info-sign')).add_to(s_map)
elif condition[index_draw] == 'Network μλ¬':
folium.Marker([df.loc[index_draw, 'μλ'], df.loc[index_draw, 'κ²½λ']],
popup = '<pre>'+ df.loc[index_draw, 'μ€ν
μ΄μ
λͺ
']+ '</pre>', icon=folium.Icon(color = 'red', icon = 'info-sign')).add_to(s_map)
else:
folium.Marker([df.loc[index_draw, 'μλ'], df.loc[index_draw, 'κ²½λ']],
popup = '<pre>'+ df.loc[index_draw, 'μ€ν
μ΄μ
λͺ
']+ '</pre>', icon=folium.Icon(color = 'black', icon = 'info-sign')).add_to(s_map)
s_map.save('sejong bike.html')
κ²½λ
1 ) lat = td[3].a.attrs['onclick'].split('\'')[3]
2 ) κ΅μλμ½λ
onclick = td[3].a.attrs['onclick']
lat = onclick.split(',')[1]
lat = lat.replace('\'','').strip()μλ
1 ) lon = td[3].a.attrs['onclick'].split('\'')[5]
2 ) κ΅μλμ½λ
lon = onclick.split(',')[2]
lon = lon.replace(');','').replace('\'','').strip()
https://colab.research.google.com/drive/1DbjiXZEBagugta0MVgQz5oqM98gbQ-rY?usp=sharing
μΈμ’
μ΄μΈλ§ ν¬λ‘€λ§μ ν΄λ³Όλ μ²μμ μλμ κ²½λλ₯Ό μ΄λ»κ² λ°μμμΌ νλ λ§λ§νλ€. κ·Έλμ μ΄μ¬ν μμΉνλ€ ..^^... νμ μλκ²½λ μ΄λ»κ² λ°μλμ§ μλ²½ν μ΄ν΄νμ§ λͺ»ν μνμ¬μ κ²μμ΄λ₯Ό λ체 λλΌκ³ μ³μΌλλ κ³ λ―Όνλλ° μ΄κ²μ κ² κ²μνλ€λ³΄λκΉ μνλ μ 보λ₯Ό μ°Ύμκ³ μ±κ³΅νλ€.γ
γ
γ
λ΄κ° μ°Ύμ λ°©λ²μ΄ μμ§ν μλ²½ν μ λ΅μ΄λΌκ³ μκ°νλλ°, λ€λ₯Έ λ°μ΄ν°λ₯Ό ν¬λ‘€λ§ν λ μ νν μ§μ μ μ ν΄μ£Όλ©΄ μ μ λ μλ μλ€κ³ ν΄μ lat = td[3].find('a')['onclick'].split('\'')[3] λ§κ³ onclickμ΄λΌλ μμ±μ μ°Ύμκ²μ΄λΌλ μλ―Έλ‘ lat = td[3].find('a').attrs['onclick'].split('\'')[3]μΌλ‘ κ³ μ³μ£Όμλ€. μ΄λ ΅λ€ γ
γ
..... κ·Έλλ μμΉν΄μ μ°Ύκ³ μ½λλ₯Ό λλ €λ΄€λλ° μ€λ₯ μλ¬μλ λ무μ’μλ€ ~~π€‘ μ΄λμ μ½λ© μ’μνλ보λ€,, μμ§μ μ½λ©μ μ’μνμ§μμ§λ§ λ
Έλ ₯ν΄λ³΄γ
μΌμ§.... μ½λ©μ΄ λ μ’μν΄μ€¬μΌλ©΄ λ§μ§λͺ»ν΄ μ’μν΄μ€ν
λ° λ μ’μν μκ°μ΄ μμ΄λ³΄μ¬μ λ΄κ° λ
Έλ ₯ν΄μΌλλκ²μ§μ¦λγ
^γ
..
μ½λ©... λ κ°κ³ λ§κ² μ΄ γ γ γ γ γ γ γ γ γ γ νμ΄μ¬μ μλ°λ¨Ήλ κ·Έλ κΉμ§ νμ΄ν